Thread: What's wrong with my code?

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    85

    What's wrong with my code?

    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

    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 ?
    Last edited by Kelvin; 07-17-2002 at 01:29 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well before you do any more web page hackery, you need to read all about the protocol here

    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

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    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 ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM