Server returned HTTP response code: 500
来源:互联网 发布:macbook pro软件推荐 编辑:程序博客网 时间:2024/05/17 20:25
今天做项目,需要跟第三方通信,用第三方的 httpclient 可以正常请求。但是换用下面的代码。确返回 Server returned HTTP response code: 500
当时,我一想,不对呀,第三方请求可以,而且直接用浏览器用地址也可以正常访问,那为什么会返回提示这个呢?
前提,头信息,对方是 text/xml 编码 utf-8
代码如下:
try {
URL urls = new URL(url);
HttpURLConnection uc = (HttpURLConnection) urls.openConnection();
uc.setRequestMethod("POST");
uc.setRequestProperty("ContentType","text/xml;charset=utf-8");
uc.setRequestProperty("charset", "UTF-8");
//uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT //5.1)AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11");
uc.setDoOutput(true);
uc.setDoInput(true);
//uc.setReadTimeout(10000);
//uc.setConnectTimeout(10000);
if(!StringUtils.isBlank(message)){
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
dos.write(message.getBytes("UTF-8"));
dos.flush();
}
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8"));
String readLine = "";
while ((readLine = in.readLine()) != null) {
sb.append(readLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
///释放资源
}
注意看粗体,主要是这个头信息设置有误,导致服务器返回 500错误。。
另外,在网上也GOOLGE了下,也有的是说是第二个粗字体处,没有设置的原因,说是安全性。
以此记录下。
当时,我一想,不对呀,第三方请求可以,而且直接用浏览器用地址也可以正常访问,那为什么会返回提示这个呢?
前提,头信息,对方是 text/xml 编码 utf-8
代码如下:
try {
URL urls = new URL(url);
HttpURLConnection uc = (HttpURLConnection) urls.openConnection();
uc.setRequestMethod("POST");
uc.setRequestProperty("ContentType","text/xml;charset=utf-8");
uc.setRequestProperty("charset", "UTF-8");
//uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT //5.1)AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11");
uc.setDoOutput(true);
uc.setDoInput(true);
//uc.setReadTimeout(10000);
//uc.setConnectTimeout(10000);
if(!StringUtils.isBlank(message)){
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
dos.write(message.getBytes("UTF-8"));
dos.flush();
}
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8"));
String readLine = "";
while ((readLine = in.readLine()) != null) {
sb.append(readLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
///释放资源
}
注意看粗体,主要是这个头信息设置有误,导致服务器返回 500错误。。
另外,在网上也GOOLGE了下,也有的是说是第二个粗字体处,没有设置的原因,说是安全性。
以此记录下。
0 0
- Server returned HTTP response code: 500
- Server returned HTTP response code: 500 for URL: http.......错误
- Server returned HTTP response code: 500 for URL解决方法
- Server returned HTTP response code: 500 for URL
- Server returned HTTP response code: 500 for URL:
- 解决Server returned HTTP response code: 505
- Server returned HTTP response code: 505 问题解决
- 关于Server returned HTTP response code: 403 for URL
- Server returned HTTP response code: 416 for UR
- 关于Server returned HTTP response code: 403 for URL
- 解决接口Server returned HTTP response code: 505
- java.io.IOException Server returned HTTP response code 415
- 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: 500 for url:
- [报错总结]java.io.IOException: Server returned HTTP response code: 500 for URL:
- hession开发遇到的问题 Server returned HTTP response code: 500 for URL:
- java.io.IOException: Server returned HTTP response code: 500 for URL解决办法
- 如何撰写软件详细设计内容?
- Vim一些常用命令
- 使用Websocket实现消息推送(上)
- C++使用libcurl做HttpClient
- php56w的rpm源
- Server returned HTTP response code: 500
- MPush开源消息推送系统:简洁、安全、支持集群
- 网络通信之UDP
- 建议1: 正确操作字符串
- hdu 1856求集合中元素个数
- hql语句犯得蠢错book is not mapped
- HIHO #1196 : 高斯消元·二(异或方程组)
- 学会3招缓解家务病 身体才能更健康
- could not get batchedbridge, make sure your bundle is packaged correctly