Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Using BSD sockets or, if you're somewhat limited, say you have some RTOS, some simpler TCP stack, like lwIP, you can form the GET/POST request.</p> <p>There are a number of open-source implementations. See the "happyhttp" as a sample ( <a href="http://scumways.com/happyhttp/happyhttp.html" rel="noreferrer">http://scumways.com/happyhttp/happyhttp.html</a> ). I know, it is C++, not C, but the only thing that is "C++-dependant" there is a string/array management, so it is easily ported to pure C.</p> <p>Beware, there are no "packets", since HTTP is usually transfered over the TCP connection, so technically there is only a stream of symbols in RFC format. Since http requests are usually done in a connect-send-disconnect manner, one might actually call this a "packet".</p> <p>Basically, once you have an open socket (sockfd) "all" you have to do is something like</p> <pre><code>char sendline[MAXLINE + 1], recvline[MAXLINE + 1]; char* ptr; size_t n; /// Form request snprintf(sendline, MAXSUB, "GET %s HTTP/1.0\r\n" // POST or GET, both tested and works. Both HTTP 1.0 HTTP 1.1 works, but sometimes "Host: %s\r\n" // but sometimes HTTP 1.0 works better in localhost type "Content-type: application/x-www-form-urlencoded\r\n" "Content-length: %d\r\n\r\n" "%s\r\n", page, host, (unsigned int)strlen(poststr), poststr); /// Write the request if (write(sockfd, sendline, strlen(sendline))&gt;= 0) { /// Read the response while ((n = read(sockfd, recvline, MAXLINE)) &gt; 0) { recvline[n] = '\0'; if(fputs(recvline,stdout) == EOF) { cout &lt;&lt; ("fputs erros"); } /// Remove the trailing chars ptr = strstr(recvline, "\r\n\r\n"); // check len for OutResponse here ? snprintf(OutResponse, MAXRESPONSE,"%s", ptr); } } </code></pre>
 

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