264 lines
18 KiB
HTML
264 lines
18 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>SFML - Simple and Fast Multimedia Library</title>
|
|
<meta http-equiv="Content-Type" content="text/html;"/>
|
|
<meta charset="utf-8"/>
|
|
<!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
|
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="banner-container">
|
|
<div id="banner">
|
|
<span id="sfml">SFML 2.5.1</span>
|
|
</div>
|
|
</div>
|
|
<div id="content">
|
|
<!-- Generated by Doxygen 1.8.14 -->
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="navrow2" class="tabs2">
|
|
<ul class="tablist">
|
|
<li><a href="annotated.html"><span>Class List</span></a></li>
|
|
<li><a href="classes.html"><span>Class Index</span></a></li>
|
|
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
|
<li><a href="functions.html"><span>Class Members</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><b>sf</b></li><li class="navelem"><a class="el" href="classsf_1_1Http.html">Http</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#nested-classes">Classes</a> |
|
|
<a href="#pub-methods">Public Member Functions</a> |
|
|
<a href="classsf_1_1Http-members.html">List of all members</a> </div>
|
|
<div class="headertitle">
|
|
<div class="title">sf::Http Class Reference<div class="ingroups"><a class="el" href="group__network.html">Network module</a></div></div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>A HTTP client.
|
|
<a href="classsf_1_1Http.html#details">More...</a></p>
|
|
|
|
<p><code>#include <<a class="el" href="Http_8hpp_source.html">Http.hpp</a>></code></p>
|
|
<div class="dynheader">
|
|
Inheritance diagram for sf::Http:</div>
|
|
<div class="dyncontent">
|
|
<div class="center">
|
|
<img src="classsf_1_1Http.png" usemap="#sf::Http_map" alt=""/>
|
|
<map id="sf::Http_map" name="sf::Http_map">
|
|
<area href="classsf_1_1NonCopyable.html" title="Utility class that makes any derived class non-copyable. " alt="sf::NonCopyable" shape="rect" coords="0,0,105,24"/>
|
|
</map>
|
|
</div></div>
|
|
<table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
|
|
Classes</h2></td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Http_1_1Request.html">Request</a></td></tr>
|
|
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Define a HTTP request. <a href="classsf_1_1Http_1_1Request.html#details">More...</a><br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Http_1_1Response.html">Response</a></td></tr>
|
|
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Define a HTTP response. <a href="classsf_1_1Http_1_1Response.html#details">More...</a><br /></td></tr>
|
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
|
|
Public Member Functions</h2></td></tr>
|
|
<tr class="memitem:abe2360194f99bdde402c9f97a85cf067"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Http.html#abe2360194f99bdde402c9f97a85cf067">Http</a> ()</td></tr>
|
|
<tr class="memdesc:abe2360194f99bdde402c9f97a85cf067"><td class="mdescLeft"> </td><td class="mdescRight">Default constructor. <a href="#abe2360194f99bdde402c9f97a85cf067">More...</a><br /></td></tr>
|
|
<tr class="separator:abe2360194f99bdde402c9f97a85cf067"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a79efd844a735f083fcce0edbf1092385"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Http.html#a79efd844a735f083fcce0edbf1092385">Http</a> (const std::string &host, unsigned short port=0)</td></tr>
|
|
<tr class="memdesc:a79efd844a735f083fcce0edbf1092385"><td class="mdescLeft"> </td><td class="mdescRight">Construct the HTTP client with the target host. <a href="#a79efd844a735f083fcce0edbf1092385">More...</a><br /></td></tr>
|
|
<tr class="separator:a79efd844a735f083fcce0edbf1092385"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a55121d543b61c41cf20b885a97b04e65"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Http.html#a55121d543b61c41cf20b885a97b04e65">setHost</a> (const std::string &host, unsigned short port=0)</td></tr>
|
|
<tr class="memdesc:a55121d543b61c41cf20b885a97b04e65"><td class="mdescLeft"> </td><td class="mdescRight">Set the target host. <a href="#a55121d543b61c41cf20b885a97b04e65">More...</a><br /></td></tr>
|
|
<tr class="separator:a55121d543b61c41cf20b885a97b04e65"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aaf09ebfb5e00dcc82e0d494d5c6a9e2a"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Http_1_1Response.html">Response</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Http.html#aaf09ebfb5e00dcc82e0d494d5c6a9e2a">sendRequest</a> (const <a class="el" href="classsf_1_1Http_1_1Request.html">Request</a> &request, <a class="el" href="classsf_1_1Time.html">Time</a> timeout=<a class="el" href="classsf_1_1Time.html#a8db127b632fa8da21550e7282af11fa0">Time::Zero</a>)</td></tr>
|
|
<tr class="memdesc:aaf09ebfb5e00dcc82e0d494d5c6a9e2a"><td class="mdescLeft"> </td><td class="mdescRight">Send a HTTP request and return the server's response. <a href="#aaf09ebfb5e00dcc82e0d494d5c6a9e2a">More...</a><br /></td></tr>
|
|
<tr class="separator:aaf09ebfb5e00dcc82e0d494d5c6a9e2a"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p>A HTTP client. </p>
|
|
<p><a class="el" href="classsf_1_1Http.html" title="A HTTP client. ">sf::Http</a> is a very simple HTTP client that allows you to communicate with a web server.</p>
|
|
<p>You can retrieve web pages, send data to an interactive resource, download a remote file, etc. The HTTPS protocol is not supported.</p>
|
|
<p>The HTTP client is split into 3 classes: </p><ul>
|
|
<li><a class="el" href="classsf_1_1Http_1_1Request.html" title="Define a HTTP request. ">sf::Http::Request</a> </li>
|
|
<li><a class="el" href="classsf_1_1Http_1_1Response.html" title="Define a HTTP response. ">sf::Http::Response</a> </li>
|
|
<li><a class="el" href="classsf_1_1Http.html" title="A HTTP client. ">sf::Http</a></li>
|
|
</ul>
|
|
<p><a class="el" href="classsf_1_1Http_1_1Request.html" title="Define a HTTP request. ">sf::Http::Request</a> builds the request that will be sent to the server. A request is made of: </p><ul>
|
|
<li>a method (what you want to do) </li>
|
|
<li>a target URI (usually the name of the web page or file) </li>
|
|
<li>one or more header fields (options that you can pass to the server) </li>
|
|
<li>an optional body (for POST requests)</li>
|
|
</ul>
|
|
<p><a class="el" href="classsf_1_1Http_1_1Response.html" title="Define a HTTP response. ">sf::Http::Response</a> parse the response from the web server and provides getters to read them. The response contains: </p><ul>
|
|
<li>a status code </li>
|
|
<li>header fields (that may be answers to the ones that you requested) </li>
|
|
<li>a body, which contains the contents of the requested resource</li>
|
|
</ul>
|
|
<p><a class="el" href="classsf_1_1Http.html" title="A HTTP client. ">sf::Http</a> provides a simple function, SendRequest, to send a <a class="el" href="classsf_1_1Http_1_1Request.html" title="Define a HTTP request. ">sf::Http::Request</a> and return the corresponding <a class="el" href="classsf_1_1Http_1_1Response.html" title="Define a HTTP response. ">sf::Http::Response</a> from the server.</p>
|
|
<p>Usage example: </p><div class="fragment"><div class="line"><span class="comment">// Create a new HTTP client</span></div><div class="line"><a class="code" href="classsf_1_1Http.html">sf::Http</a> http;</div><div class="line"></div><div class="line"><span class="comment">// We'll work on http://www.sfml-dev.org</span></div><div class="line">http.<a class="code" href="classsf_1_1Http.html#a55121d543b61c41cf20b885a97b04e65">setHost</a>(<span class="stringliteral">"http://www.sfml-dev.org"</span>);</div><div class="line"></div><div class="line"><span class="comment">// Prepare a request to get the 'features.php' page</span></div><div class="line"><a class="code" href="classsf_1_1Http_1_1Request.html">sf::Http::Request</a> request(<span class="stringliteral">"features.php"</span>);</div><div class="line"></div><div class="line"><span class="comment">// Send the request</span></div><div class="line"><a class="code" href="classsf_1_1Http_1_1Response.html">sf::Http::Response</a> response = http.<a class="code" href="classsf_1_1Http.html#aaf09ebfb5e00dcc82e0d494d5c6a9e2a">sendRequest</a>(request);</div><div class="line"></div><div class="line"><span class="comment">// Check the status code and display the result</span></div><div class="line"><a class="code" href="classsf_1_1Http_1_1Response.html#a663e071978e30fbbeb20ed045be874d8">sf::Http::Response::Status</a> status = response.<a class="code" href="classsf_1_1Http_1_1Response.html#a4271651703764fd9a7d2c0315aff20de">getStatus</a>();</div><div class="line"><span class="keywordflow">if</span> (status == <a class="code" href="classsf_1_1Http_1_1Response.html#a663e071978e30fbbeb20ed045be874d8a0158f932254d3f09647dd1f64bd43832">sf::Http::Response::Ok</a>)</div><div class="line">{</div><div class="line"> std::cout << response.<a class="code" href="classsf_1_1Http_1_1Response.html#ab3bfc29867563aa815f6460eeea16136">getBody</a>() << std::endl;</div><div class="line">}</div><div class="line"><span class="keywordflow">else</span></div><div class="line">{</div><div class="line"> std::cout << <span class="stringliteral">"Error "</span> << status << std::endl;</div><div class="line">}</div></div><!-- fragment -->
|
|
<p class="definition">Definition at line <a class="el" href="Http_8hpp_source.html#l00046">46</a> of file <a class="el" href="Http_8hpp_source.html">Http.hpp</a>.</p>
|
|
</div><h2 class="groupheader">Constructor & Destructor Documentation</h2>
|
|
<a id="abe2360194f99bdde402c9f97a85cf067"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#abe2360194f99bdde402c9f97a85cf067">◆ </a></span>Http() <span class="overload">[1/2]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">sf::Http::Http </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Default constructor. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a79efd844a735f083fcce0edbf1092385"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a79efd844a735f083fcce0edbf1092385">◆ </a></span>Http() <span class="overload">[2/2]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">sf::Http::Http </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const std::string & </td>
|
|
<td class="paramname"><em>host</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">unsigned short </td>
|
|
<td class="paramname"><em>port</em> = <code>0</code> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Construct the HTTP client with the target host. </p>
|
|
<p>This is equivalent to calling setHost(host, port). The port has a default value of 0, which means that the HTTP client will use the right port according to the protocol used (80 for HTTP). You should leave it like this unless you really need a port other than the standard one, or use an unknown protocol.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">host</td><td>Web server to connect to </td></tr>
|
|
<tr><td class="paramname">port</td><td>Port to use for connection </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
|
|
</div>
|
|
</div>
|
|
<h2 class="groupheader">Member Function Documentation</h2>
|
|
<a id="aaf09ebfb5e00dcc82e0d494d5c6a9e2a"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aaf09ebfb5e00dcc82e0d494d5c6a9e2a">◆ </a></span>sendRequest()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="classsf_1_1Http_1_1Response.html">Response</a> sf::Http::sendRequest </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const <a class="el" href="classsf_1_1Http_1_1Request.html">Request</a> & </td>
|
|
<td class="paramname"><em>request</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype"><a class="el" href="classsf_1_1Time.html">Time</a> </td>
|
|
<td class="paramname"><em>timeout</em> = <code><a class="el" href="classsf_1_1Time.html#a8db127b632fa8da21550e7282af11fa0">Time::Zero</a></code> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Send a HTTP request and return the server's response. </p>
|
|
<p>You must have a valid host before sending a request (see setHost). Any missing mandatory header field in the request will be added with an appropriate value. Warning: this function waits for the server's response and may not return instantly; use a thread if you don't want to block your application, or use a timeout to limit the time to wait. A value of <a class="el" href="classsf_1_1Time.html#a8db127b632fa8da21550e7282af11fa0" title="Predefined "zero" time value. ">Time::Zero</a> means that the client will use the system default timeout (which is usually pretty long).</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">request</td><td><a class="el" href="classsf_1_1Http_1_1Request.html" title="Define a HTTP request. ">Request</a> to send </td></tr>
|
|
<tr><td class="paramname">timeout</td><td>Maximum time to wait</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>Server's response </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a55121d543b61c41cf20b885a97b04e65"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a55121d543b61c41cf20b885a97b04e65">◆ </a></span>setHost()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void sf::Http::setHost </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const std::string & </td>
|
|
<td class="paramname"><em>host</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">unsigned short </td>
|
|
<td class="paramname"><em>port</em> = <code>0</code> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Set the target host. </p>
|
|
<p>This function just stores the host address and port, it doesn't actually connect to it until you send a request. The port has a default value of 0, which means that the HTTP client will use the right port according to the protocol used (80 for HTTP). You should leave it like this unless you really need a port other than the standard one, or use an unknown protocol.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">host</td><td>Web server to connect to </td></tr>
|
|
<tr><td class="paramname">port</td><td>Port to use for connection </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
|
|
</div>
|
|
</div>
|
|
<hr/>The documentation for this class was generated from the following file:<ul>
|
|
<li><a class="el" href="Http_8hpp_source.html">Http.hpp</a></li>
|
|
</ul>
|
|
</div><!-- contents -->
|
|
</div>
|
|
<div id="footer-container">
|
|
<div id="footer">
|
|
SFML is licensed under the terms and conditions of the <a href="https://www.sfml-dev.org/license.php">zlib/png license</a>.<br>
|
|
Copyright © Laurent Gomila ::
|
|
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> ::
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|