67,515
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Submitted URI too large!</title>
<link rev="made" href="mailto:postmaster@localhost" />
<style type="text/css"><!--/*--><![CDATA[/*><!--*/
body { color: #000000; background-color: #FFFFFF; }
a:link { color: #0000CC; }
p, address {margin-left: 3em;}
span {font-size: smaller;}
/*]]>*/--></style>
</head>
<body>
<h1>Submitted URI too large!</h1>
<p>
The length of the requested URL exceeds the capacity limit for
this server. The request cannot be processed.
</p>
<p>
If you think this is a server error, please contact
the <a href="mailto:postmaster@localhost">webmaster</a>.
</p>
<h2>Error 414</h2>
<address>
<a href="/">localhost</a><br />
<span>Apache/2.4.18 (Win32) PHP/5.6.16</span>
</address>
</body>
</html>
public static String doPost(String urlString, Map<String, String> params, String encode){
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(urlString);
try {
Set<String> keys = params.keySet();
NameValuePair[] values = new NameValuePair[keys.size()];
int i = 0;
for(String key : keys){
NameValuePair v = new NameValuePair();
v.setName(key);
v.setValue(params.get(key));
values[i] = v;
i ++;
}
// 设置超时时间15s
client.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
// 设置读取数据超时时间
client.getHttpConnectionManager().getParams().setSoTimeout(10000);// 设置读数据超时时间(单位毫秒)
client.getHttpConnectionManager().getParams().setMaxTotalConnections(500);
client.getHttpConnectionManager().getParams().setDefaultMaxConnectionsPerHost(50);
client.getHttpConnectionManager().getParams().setStaleCheckingEnabled(true);
method.getParams().setHttpElementCharset(encode);
method.getParams().setContentCharset(encode);
method.setRequestBody(values); // 使用 POST 方式提交数据
client.executeMethod(method); //返回的状态
String response = method.getResponseBodyAsString();
return response; //response就是最后得到的结果
} catch (Exception e) {
e.printStackTrace();
}finally{
if(method != null){
method.releaseConnection();
}
if(client != null){
((SimpleHttpConnectionManager)client.getHttpConnectionManager()).closeIdleConnections(0);
}
}
return "";
}