java.io.IOException: Server returned HTTP response code: 411
This is because some Web servers will reject a request made to the Web server using HTTP POST without providing the appropriate BODY data. We can see the official story disseminated in explanation of the error code 411 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) :
10.4.12 411 Length Required
The server refuses to accept the request without a defined Content- Length. The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message.
The solution is to set content-length =0 in the request header and write an empty BODY data into the OutputStream.
URL the URL = new URL (” http://www.webservicex.net/MortgageIndex.asmx/GetCurrentMortgageIndexByWeekly “);
final HttpURLConnection conn = (HttpURLConnection) url.openconnection ();
conn. SetDoInput (true);
conn. SetDoOutput (true);
conn. SetRequestMethod (” POST “);
conn. SetRequestProperty (” the content-type “, “text/XML”);
conn. SetRequestProperty (” the Content – Length “, “0”);
DataOutputStream OS = new DataOutputStream(conn. GetOutputStream ());
OS. Write (“. “getBytes (” utf-8″), 0, 0).
OS. Flush ();
OS. The close ();
conn. The connect ();
InputStream is = conn. GetInputStream ();
Integer code = conn. GetResponseCode ();
final String contentType = conn. GetContentType ();
System. Out. Println (code + + contentType “:”);
Read More:
- IIS “Bad Request – Request Too Long. HTTP Error 400. The size of the request headers is too long.”
- Four ways to get Django parameters in request
- PHP big file upload problem (500m or above)
- The remote server returned an error: (417) Expectation failed
- Springboot project: error parsing HTTP request header note: further occurrences of HTTP request parsing
- How to Solve mybatis returns null when querying Oracle database with char type field
- can’t set headers after they are sent
- Quirky error 18: transfer closed with outstanding read data rem
- Nginx modifies the front end request size limit (413 request entity too large)
- Wechat payment API V3 payment notice asynchronous signature verification failed
- HTTPError HTTP Error 500 INTERNAL SERVER ERROR
- HTTP error 401 and 403 detailed explanation and solution
- Regarding [java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Boolean], combined with examples
- React Native Network Request Failed solution
- Python TCP socket programming: send returns broken pipe error?
- vector length_error
- PHP & nbsp; built in server array
- Encapsulation of adding, deleting and modifying database by JDBC
- The problem that headers [‘content-type ‘] does not work is set in the Axios get method request interface
- Router DIO network request: dioerror[ DioErrorType.RESPONSE ]: HTTP status error [400] or [500]