Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL解决方案
来源:互联网 发布:unity3d 上海培训 编辑:程序博客网 时间:2024/04/29 17:46
最近一次项目上线时遇到一个挠头的bug,开发环境和测试环境都是正常的,一旦到了生产环境就报“网络超时”,经过仔细分析,最终定位到了相关的代码段,于是在本地进行调试。
流程大致是这样的,页面发送一个ajax请求,后台接收到这个ajax请求之后会请求一个指定的url,问题就出在了请求这个url上。本地调试的情况是这样的,如果把这个url替换成本地的,则正常,如果替换成了远程指定的url,则tomcat会报出错误:Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL xxx。
最终解决方案如下,下面是相关代码片段:
String params = request.getParameter("params");
JSONObject msgObj = JSON.parseObject(params);
result = getResponseFromUrl(mgw, new String(msgObj.toString().getBytes("iso8859-1"), "UTF-8").replaceAll("\"", "'").getBytes());
最主要的地方是一次转码和一次替换,一次转码是指从iso8859-1转换成UTF-8,一次替换是指把json字符串中的所有的双引号替换为单引号。
0 0
- Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL解决方案
- java.io.IOException: Server returned HTTP response code: 400 for URL解决方法
- java.io.IOException: Server returned HTTP response code: 403 for URL: http://
- java.io.IOException: Server returned HTTP response code: 505 for URL: http://localhost:8080/fish/add
- java.io.IOException: Server returned HTTP response code: 403 for URL: http://
- java.io.IOException: Server returned HTTP response code: 403 for URL: http://的解决办法
- java.io.IOException: Server returned HTTP response code: 500 for URL
- java.io.IOException: Server returned HTTP response code: 500 for URL
- 用户代理及 java.io.IOException: Server returned HTTP response code: 403 for URL
- java.io.IOException: Server returned HTTP response code: 505 for URL: 问题
- java.io.ioexception: server returned http response code: 500 for url:
- java.io.IOException: Server returned HTTP response code: 403 for URL
- [报错总结]java.io.IOException: Server returned HTTP response code: 500 for URL:
- 用户代理异常:java.io.IOException: Server returned HTTP response code: 403 for URL
- java.io.IOException: Server returned HTTP response code: 500 for URL解决办法
- java.io.IOException: Server returned HTTP response code: 405 for URL: *********处理方法
- java.io.IOException: Server returned HTTP response code: 415 for URL:xxxxxx
- java.io.IOException: Server returned HTTP response code: 405 for URL:
- Django之celery分布式异步任务队列
- python学习——电子邮件
- 【NOIP模拟】颜料大乱斗
- Java基础技巧
- "Xcode"意外退出
- Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL解决方案
- HDU - 1021 Fibonacci Again
- 多个tomcat 共存需要修改的端口
- java/设计原则
- CodeForces 131B
- SwipeRefreshLayout实现下拉刷新
- Java连接PostgreSQL数据库
- 创建新节点
- Java集成kettle