I was trying to send a get request to a website but always return error 400 bad request. I’m wondering if my get request is wrong or not. Here it is;
socketOut.println("GET " + req.url + " HTTP/1.1\r\n");
socketOut.flush();
I can do it by using URLConnection but as a second way I’m using socket. So I’m sending this request and readinng bytes. I checked what it returns to me from website and of course it returns bad request error page. Any suggestion? By the way req.url returns a url not something like /asd.html but this http://www.stackoverflow.com/asd.html
printlnmay use\nas new line instead of\r\nwhich might be required. Try using\r\ndirectly.HTTP 1.1 requires
Hostheader. Try:or: