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
Zeroth
Posted: 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
Posted: 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
Posted: 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.