Java Http Client get 408 Request Time-out -
i developing simple http client, have problem here:
when using telnet on windows command line:
telnet download.microsoft.com 80 head / http/1.1 host: download.microsoft.com
response: 301 moved permanently
head /download/7/a/9/7a9ebb22-8dc8-40a2-802d-b4cc343a928e/proplussp2013-kb2817430-fullfile-x86-vi-vn.exe http/1.1 host: download.microsoft.com
response: 200 ok
when using program (eclipse ide, jre8) java code:
import java.io.*; import java.net.*; public class main { public static datainputstream in; public static bufferedwriter out; public static string host = "download.microsoft.com"; public static int port = 80; public static socket soc; public static string getheader(string uri) throws ioexception{ string httprequest = "head " + uri + "\r\n" + "http/1.1\r\n" + "host:" + host + "\r\n"; string httpresponse = ""; int read; out.write(httprequest); out.flush(); while ((read = in.read()) != -1) httpresponse += (char)read; return httpresponse; } public static void main(string[] args) throws unknownhostexception, ioexception{ soc = new socket(host, port); in = new datainputstream(soc.getinputstream()); out= new bufferedwriter(new outputstreamwriter(soc.getoutputstream())); system.out.println(getheader("/")); soc.close(); } }
with getheader("/")
run 20s response http/1.0 408 request time-out
with getheader("/download/7/a/9/7a9ebb22-8dc8-40a2-802d-b4cc343a928e/proplussp2013-kb2817430-fullfile-x86-vi-vn.exe")
http/1.0 408 request time-out
my code work ok host. know host download.microsoft.com not normal accessible, why 2 method above give different result?
thanks!
dump contents of httprequest screen , you'll see you're building broken request (crlf instead of sp before http-version).
furhtermore you're missing additional crlf (see http://greenbytes.de/tech/webdav/rfc7230.html#http.message)
Comments
Post a Comment