
-----------------------------------
greenapplesodaex
Fri Oct 03, 2008 7:31 am

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)


    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

-----------------------------------
Zeroth
Fri Oct 03, 2008 8:50 am

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
Fri Oct 03, 2008 2:18 pm

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
Fri Oct 03, 2008 3:29 pm

Re: HTTP/1.1 400 Bad Request,  why?
-----------------------------------
didnt see mto work... i guess i have to email the tutor
edit:
got it
Ensure that your HTTP request ends with a sequence of "\r\n\r\n". Otherwise web-servers will ignore your requests.
