Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To access a resource on some host you just specify the path to the resource in the first line of the request, just after the 'GET'. E.g. check <a href="http://www.jmarshall.com/easy/http/#http1.1" rel="nofollow">http://www.jmarshall.com/easy/http/#http1.1</a></p> <pre><code>GET /path/file.html HTTP/1.1 Host: www.host1.com:80 [blank line here] </code></pre> <p>I'd also recomend using some portable library like Boost.ASIO instead of sockets. But I'd strongly recomend you to use some existing, portable library implementing HTTP protocol. Of course only if it is not a matter of learning how to implement it.</p> <p>Even if you want to implement it by yourself it'd be worth knowing the existing solutions. For instance this is how you can get a webpage using cpp-netlib (<a href="http://cpp-netlib.org/0.10.1/index.html" rel="nofollow">http://cpp-netlib.org/0.10.1/index.html</a>):</p> <pre><code>using namespace boost::network; using namespace boost::network::http; client::request request_("http://127.0.0.1:8000/"); request_ &lt;&lt; header("Connection", "close"); client client_; client::response response_ = client_.get(request_); std::string body_ = body(response_); </code></pre> <p>This is how you can do it using cURL library (<a href="http://curl.haxx.se/libcurl/c/simple.html" rel="nofollow">http://curl.haxx.se/libcurl/c/simple.html</a>):</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;curl/curl.h&gt; int main(void) { CURL *curl; CURLcode res; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); /* example.com is redirected, so we tell libcurl to follow redirection */ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); } return 0; } </code></pre> <p>Both libraries are portable but if you'd like to use some Windows-specific API you might check WinINet (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383630%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/aa383630%28v=vs.85%29.aspx</a>) but it's less pleasant to use.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload