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?
Following the voice in heart.
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);
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: