How To Make A Get Request Over Socket C

[Solved] How To Make A Get Request Over Socket C | Vb - Code Explorer | yomemimo.com
Question : how to make a get request over socket c

Answered by : worried-wallaby-9pbppkdum6x5

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))>= 0)
{ /// Read the response while ((n = read(sockfd, recvline, MAXLINE)) > 0) { recvline[n] = '\0'; if(fputs(recvline, stdout) == EOF) { printf("fputs() error\n"); } /// Remove the trailing chars ptr = strstr(recvline, "\r\n\r\n"); // check len for OutResponse here ? snprintf(OutResponse, MAXRESPONSE,"%s", ptr); }
}

Source : https://stackoverflow.com/questions/11208299/how-to-make-an-http-get-request-in-c-without-libcurl | Last Update : Sat, 20 Feb 21

Answers related to how to make a get request over socket c

Code Explorer Popular Question For Vb