`
wrong1111
  • 浏览: 249982 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论

Server returned HTTP response code: 500

    博客分类:
  • java
阅读更多
今天做项目,需要跟第三方通信,用第三方的 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了下,也有的是说是第二个粗字体处,没有设置的原因,说是安全性。
以此记录下。
分享到:
评论

相关推荐

    BasicAuth2.java

    java.io.IOException: Server returned HTTP response code: 403 for URL 处理过程记录 BASIC AUTH2 POST接口,解决403问题

    提示“处理URL时服务器出错”和“HTTP 500错误“的解决方法

    在使用Web服务或浏览网页时,用户可能会遇到“处理URL时服务器出错”或“HTTP 500错误”的情况,这些错误信息通常表明服务器在处理请求时发生了问题。了解这两种错误的原因及解决方法对于排查问题至关重要。 1. **...

    错误429处理(悟用书生制)

    429问题处理办法(悟用书生)

    解决Java URL.openConnection().connect();报错:Server returned HTTP re

    声明 1、本解决方法适用于浏览器正常访问,但是代码请求报错Http 403错误的场景; 概述: 1、Http 403报错是常见的网络错误提示,表示...报错Server returned HTTP response code 403 for URL.txt》里面的内容操作。

    Java下载m3u8文件列表中的TS文件到本地工具类

    m3u8是一种媒体播放列表格式,它包含...5.2、解决报错:Server returned HTTP response code: 403 for URL。 若下载下来有合并需求的,可以看下合并工具:https://download.csdn.net/download/gongjin28_csdn/35906117

    maven 远程部署tomcat

    如果在部署时出现 `Server returned HTTP response code: 403` 异常,可能是因为 Tomcat 7 引用的角色是 `manager-script` 而不是 `manager`,或者 Tomcat 7 对于部署(deploy)需要的角色应该是 `manager-script` ...

    计算机网络第六版答案

    21. The maximum emission rate is 500 packets/sec and the maximum transmission rate is 350 packets/sec. The corresponding traffic intensity is 500/350 =1.43 > 1. Loss will eventually occur for each ...

    检查网站是否存在 opensSSL

    print 'WARNING: server returned more data than it should - server is vulnerable!' else: print 'Server processed malformed heartbeat, but did not return any extra data.' return True if typ == 21:...

    php.ini-development

    interesting side-effects depending on your application and web server. ; You may be able to send headers and cookies after you've already sent output ; through print or echo. You also may see ...

    webservice-ajax

    You have a functioning client-side JavaScript code that calls server-side Web Service and treats returned response. If we supply empty input value to the GetServerResponse method of ...

    Know Your HTTP Status Codes-计算机科学

    HTTP status codes are returned in the response. They each consist of a three digit numerical code and a text description (the text description is simply advisory, and may be translated to other ...

    Turbo C++ 3.0[DISK]

    Welcome to Turbo C++ Version 3.0 -------------------------------- This README file contains important information about Turbo C++. ... Options|Compiler|Advanced Code Generation and the...

    Turbo C++ 3.00[DISK]

    Welcome to Turbo C++ Version 3.0 -------------------------------- This README file contains important information about Turbo C++. ... Options|Compiler|Advanced Code Generation and the...

    Delphi7.1 Update

    * TDataSetProvider generates incorrect SQL in response to a RefreshRecord request in some cases and fails to update all fields properly (Quality Central 4014). * When TDataSetProvider obtains the DB ...

    UPnP_Programming_Guide

    4.1.10 UPNP E BAD RESPONSE [-113] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.1.11 UPNP E INVALID ACTION [-115] . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

Global site tag (gtag.js) - Google Analytics