Original Post
Hi, I am trying to generate a GET request in C code by connecting to the site on port 80. However I get a response as - This is my send request code I can't figure out what is wrong with the code. Is my GET request not framed properly ? Thanks
[Source]
400 - Bad Reqest
Your browser sent a request that this server could not understand.
client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23): /index.html
[/Source]
int SendRequest(int sockfd, const char *hostname, char *filename)
{
char getReq[4096];
memset(getReq, '\0', 4096);
// hostname has the name as "./www.websitename.com"
// hence do not copy first 2 characters
sprintf(getReq, "GET /%s HTTP/1.1\nHostname: %s\n\n",
filename, hostname+2);
int len = strlen(getReq);
while(send(sockfd, getReq, strlen(getReq), 0) < len);
}