How to change the http version number used when Java sends an http request?
typecho
typecho 2017-06-12 09:20:48
0
2
963

How to change the http version number used when Java sends an http request? How do I manually implement using http 1.1 or http 1.0?

typecho
typecho

Following the voice in heart.

reply all(2)
左手右手慢动作
Socket s = new Socket(InetAddress.getByName("stackoverflow.com"), 80);
PrintWriter pw = new PrintWriter(s.getOutputStream());
pw.println("GET / HTTP/1.1");
pw.println("Host: caiyongji.com");
pw.println("");
pw.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String t;
while((t = br.readLine()) != null) System.out.println(t);
br.close();
刘奇

It is not possible to use the HttpURLConnection that comes with Java. For details, please refer to:
http://bugs.java.com/bugdatab...

You can consider using Socket to send simple HTTP requests yourself, or use a third-party library. Take Apache HttpClient as an example:

HttpClient client = new DefaultHttpClient(); 
client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template