<head>
<title>SFML - Simple and Fast Multimedia Library</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
</head>
<body>
<div id="banner-container">
<div id="banner">
<span id="sfml">SFML</span>
</div>
</div>
<div id="content">
<!-- Generated by Doxygen 1.8.2 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.htm"><span>Main Page</span></a></li>
<li><a href="modules.htm"><span>Modules</span></a></li>
<li class="current"><a href="annotated.htm"><span>Classes</span></a></li>
<li><a href="files.htm"><span>Files</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="annotated.htm"><span>Class List</span></a></li>
<li><a href="classes.htm"><span>Class Index</span></a></li>
<li><a href="hierarchy.htm"><span>Class Hierarchy</span></a></li>
<li><a href="functions.htm"><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.htm">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.htm">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.htm">Network module</a></div></div> </div>
</div><!--header-->
<div class="contents">
<p>A HTTP client.
<a href="classsf_1_1Http.htm#details">More...</a></p>
<p><code>#include <<a class="el" href="Http_8hpp_source.htm">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.htm" 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.htm">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.htm#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.htm">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.htm#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.htm#abe2360194f99bdde402c9f97a85cf067">Http</a> ()</td></tr>
<tr class="memdesc:abe2360194f99bdde402c9f97a85cf067"><td class="mdescLeft"> </td><td class="mdescRight">Default constructor. <a href="#abe2360194f99bdde402c9f97a85cf067"></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.htm#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"></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.htm#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"></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.htm">Response</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Http.htm#aaf09ebfb5e00dcc82e0d494d5c6a9e2a">sendRequest</a> (const <a class="el" href="classsf_1_1Http_1_1Request.htm">Request</a> &request, <a class="el" href="classsf_1_1Time.htm">Time</a> timeout=<a class="el" href="classsf_1_1Time.htm#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"></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.htm" 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.</p>
<p>The HTTP client is split into 3 classes: </p>
<ul>
<li><a class="el" href="classsf_1_1Http_1_1Request.htm" title="Define a HTTP request.">sf::Http::Request</a> </li>
<li><a class="el" href="classsf_1_1Http_1_1Response.htm" title="Define a HTTP response.">sf::Http::Response</a> </li>
<li><a class="el" href="classsf_1_1Http.htm" title="A HTTP client.">sf::Http</a></li>
</ul>
<p><a class="el" href="classsf_1_1Http_1_1Request.htm" 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.htm" 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.htm" title="A HTTP client.">sf::Http</a> provides a simple function, SendRequest, to send a <a class="el" href="classsf_1_1Http_1_1Request.htm" title="Define a HTTP request.">sf::Http::Request</a> and return the corresponding <a class="el" href="classsf_1_1Http_1_1Response.htm" 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.htm" title="A HTTP client.">sf::Http</a> http;</div>
<div class="line"></div>
<div class="line">http.<a class="code" href="classsf_1_1Http.htm#a55121d543b61c41cf20b885a97b04e65" title="Set the target host.">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.htm" title="Define a HTTP request.">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.htm" title="Define a HTTP response.">sf::Http::Response</a> response = http.<a class="code" href="classsf_1_1Http.htm#aaf09ebfb5e00dcc82e0d494d5c6a9e2a" title="Send a HTTP request and return the server's response.">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.htm#a663e071978e30fbbeb20ed045be874d8" title="Enumerate all the valid status codes for a response.">sf::Http::Response::Status</a> status = response.<a class="code" href="classsf_1_1Http_1_1Response.htm#a542e9856b1dd260a83940eb982b7f19a" title="Get the response status code.">getStatus</a>();</div>
<div class="line"><span class="keywordflow">if</span> (status == <a class="code" href="classsf_1_1Http_1_1Response.htm#a663e071978e30fbbeb20ed045be874d8a0158f932254d3f09647dd1f64bd43832" title="Most common code returned when operation was successful.">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.htm#a6b74ef73051a16ebb20041495c758e22" title="Get the body of the response.">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>Definition at line <a class="el" href="Http_8hpp_source.htm#l00046">46</a> of file <a class="el" href="Http_8hpp_source.htm">Http.hpp</a>.</p>
</div><h2 class="groupheader">Constructor & Destructor Documentation</h2>
<a class="anchor" id="abe2360194f99bdde402c9f97a85cf067"></a>
<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 class="anchor" id="a79efd844a735f083fcce0edbf1092385"></a>
<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, 443 for HTTPS). 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 class="anchor" id="aaf09ebfb5e00dcc82e0d494d5c6a9e2a"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classsf_1_1Http_1_1Response.htm">Response</a> sf::Http::sendRequest </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classsf_1_1Http_1_1Request.htm">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.htm">Time</a> </td>
<td class="paramname"><em>timeout</em> = <code><a class="el" href="classsf_1_1Time.htm#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.htm#a8db127b632fa8da21550e7282af11fa0" title="Predefined "zero" time value.">Time::Zero</a> means that the client will use the system defaut 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.htm" 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 class="anchor" id="a55121d543b61c41cf20b885a97b04e65"></a>
<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, 443 for HTTPS). 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.htm">Http.hpp</a></li>
</ul>
</div><!-- contents -->
</div>
<div id="footer-container">
<div id="footer">
Copyright � Laurent Gomila ::
</div>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-41898676-1', 'srchub.org');
ga('send', 'pageview');