PDA

View Full Version : What's wrong with my code?



Kelvin
07-17-2002, 10:56 AM
I am writing a client program, simply retreving the HTML code.
However, I only get a error 400
I really don't know what the bug is...
here is the part of sending code



char cBuffer[128], cTmp[128];
const int iBufferLen = strlen(cBuffer);
while(1){
printf("\nsend>");
gets(cTmp);
if(cTmp == "") {
printf("Bye Bye...");
break;
exit(1);
}
printf("Sending...\t\t\t");
sprintf(cBuffer, "GET /%s HTTP/1.0\n", cTmp);

if(send(s, cBuffer, iBufferLen, 0) == SOCKET_ERROR) {
printf("Failed\n");
}

printf("OK\n\"%s\" is sent\n", cBuffer);
....


No matter what I type, the received message is always error 400
why ?

Salem
07-17-2002, 03:20 PM
Well before you do any more web page hackery, you need to read all about the protocol here (http://www.w3.org/Protocols/rfc1945/rfc1945)

From this, you will see

400 Bad Request

The request could not be understood by the server due to malformed
syntax. The client should not repeat the request without
modifications.


> gets(cTmp);
> if(cTmp == "") {
1. Don't use gets
2. use strcmp to compare strings

Kelvin
07-17-2002, 05:55 PM
Sorry... my program is not repeat without notification..
I just want to post the key point of my problem
sorry...

btw, why do you disencourage using gets and "if" statement ?
what is the disadvantage of using that ?