Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 HTTP/1.1 400 Bad Request, why?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
greenapplesodaex




PostPosted: Fri Oct 03, 2008 7:31 am   Post subject: HTTP/1.1 400 Bad Request, why?

Hi, I've been working on my first network asst for some time now, but I get HTTP/1.1 400 Bad Request every time. (i've tried many other website, too)

code:

    public void checkAddr(String aPath, String aSrv)
    {   srvN = aSrv;
        pathN = aPath;
       
        try
        {   Socket clientSocket = new Socket(srvN, portNum);
            DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
            BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
           
            c_s = "GET "+pathN+" HTTP/1.0"+'\r'+'\n'+"HOST: "+srvN+ '\r'+'\n';
            System.out.println("write to client out socket, the line is: "+'\n'+c_s);
            outToServer.writeBytes(c_s);
            System.out.println("wrote");
            s_c = inFromServer.readLine();
            System.out.println("got response");
            System.out.println(s_c);
            clientSocket.close();
        }
        catch (Exception e)
        {   System.out.println ("socket creation fail");
        }
    }


should I not be using socket or something? these are the exact code format I took from the class lecture.


I always get (everything before the response was my debug statement)

write to client out socket, the line is:
GET / HTTP/1.1
HOST: bbcr.uwaterloo.ca

wrote
got response
HTTP/1.1 400 Bad Request
Sponsor
Sponsor
Sponsor
sponsor
Zeroth




PostPosted: Fri Oct 03, 2008 8:50 am   Post subject: Re: HTTP/1.1 400 Bad Request, why?

Try using a higher level library. There is likely a mistake somewhere in there in your codes, and the higher level libraries don't have it. And by higher level, I mean one where you go Connect(website)->string containing html.
btiffin




PostPosted: Fri Oct 03, 2008 2:18 pm   Post subject: RE:HTTP/1.1 400 Bad Request, why?

Try changing HOST: to Host:
and I'm not sure if CRLF is the same as LF in http, so try without the \r 's as well.

Cheers
Edits; can't spell today
greenapplesodaex




PostPosted: Fri Oct 03, 2008 3:29 pm   Post subject: Re: HTTP/1.1 400 Bad Request, why?

didnt see mto work... i guess i have to email the tutor
edit:
got it
Quote:
Ensure that your HTTP request ends with a sequence of "\r\n\r\n". Otherwise web-servers will ignore your requests.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: