Reputation: 1418
I am trying to use CPP and SDL_Net to make a HTTP Client. I'm using a char [] buffer to send and receive information.
Basically, I connect to the site mentioned below on port 80:
strcpy(buffer,"GET / HTTP/1.0 \n host: nullfakenothing.freeriderwebhosting.com \n \n");
SDLNet_TCP_Send(sd, (void *)buffer, strlen(buffer)+1);
SDLNet_TCP_Recv(sd, (void *)buffer, 200)>0
But I can't get anything back (the program gets stuck on Recv). Am I using the protocol wrong or is there something against the whole TCP/HTML system?
Upvotes: 0
Views: 1133
Reputation: 48635
Your HTTP protocol has spurious spaces and should have \r\n terminators. This is untested but the HTTP should be okay. You may want to add other headers.
char buffer[1024];
std::strcpy(buffer, "GET / HTTP/1.1\r\n");
std::strcat(buffer, "Host: nullfakenothing.freeriderwebhosting.com\r\n");
std::strcat(buffer, "\r\n");
SDLNet_TCP_Send(sd, (void*) buffer, strlen(buffer));
SDLNet_TCP_Recv(sd, (void*) buffer, sizeof(buffer));
Upvotes: 2
Reputation: 123541
What you send is not HTTP but instead something which looks a little bit like HTTP if you don't look to hard. Please make yourself comfortable with the specification (like RFC2616) or at least look at some packet dumps or working code to see what you need to do their exactly. Since lots of things are wrong it makes no sense to point out specific errors.
Upvotes: 2