`
wrong1111
  • 浏览: 253317 次
  • 性别: 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问题

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

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

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

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

    java测试连接是否通畅

    if (info.indexOf("Server returned HTTP response code: 500 for URL") != -1) { success = true; } else { success = false; } } ``` 这部分代码负责处理在尝试连接和读取URL数据过程中可能遇到的各种异常。...

    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:...

    c# http post get

    - The `StatusCode` property provides access to the HTTP status code returned by the server. ### Usage Examples #### Basic Usage ```csharp HttpProc.WebClient client = new HttpProc.WebClient(); ...

    LoadRunner测试webservice

    2. **问题**:在模拟高并发压力测试时,当用户数超过 10 个之后出现 “HTTP status code 403 returned by server” 错误。 - **解决方案**:如果使用的是 Windows XP 操作系统,由于其默认并发连接数限制为 10,...

    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 ...

    Dart in Action

    - **First-Class Functions and Closures**: Dart supports first-class functions, allowing functions to be passed as arguments to other functions or returned from functions. Closures are also supported, ...

    UPnP_Programming_Guide

    - **4.1.10** `UPNP_E_BAD_RESPONSE [-113]`: Indicates a malformed response. - **4.1.11** `UPNP_E_INVALID_ACTION [-115]`: Occurs when an invalid action is attempted. - **4.1.12** `UPNP_E_FINISH [-116]`:...

    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 ...

Global site tag (gtag.js) - Google Analytics