Exception in thread ' main ' Java.io.IOException:Server returned HTTP response code:400 for URL solution

Source: Internet
Author: User
Tags response code

A recent project on the line encountered a scratching the bug, the development environment and test environment are normal, once to the production environment on the report "Network timeout", after careful analysis, the final positioning to the relevant code section, so the local debugging.

The process is roughly like this, the page sends an AJAX request, the background receives this AJAX request to request a specified URL, the problem is on the request this URL. Local debugging is the case, if you replace the cost of the URL, then normal, if replaced by the remote specified URL, then tomcat will report an error: Exception in thread "main" Java.io.IOException:Server Returned HTTP response code:400 for URL xxx.

The Final solution is as follows, and the following are the relevant code snippets:

String params = Request.getparameter ("params");
Jsonobject msgobj = Json.parseobject (params);
result = Getresponsefromurl (MGW, New String (Msgobj.tostring (). GetBytes ("Iso8859-1"), "UTF-8"). ReplaceAll ("\", "'"). GetBytes ());

The main place is a single transcoding and one substitution, one transcoding is the conversion from iso8859-1 to UTF-8, and one substitution means replacing all the double quotes in the JSON string with single quotes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.