(jsp)httpclient post 请求一直超时,求解??

来源:互联网  时间:2016/6/1 3:31:23

关于网友提出的“(jsp)httpclient post 请求一直超时,求解??”问题疑问,本网通过在网上对“(jsp)httpclient post 请求一直超时,求解??”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:(jsp)httpclient post 请求一直超时,求解??
描述:

最近在做一个接口对接,用的是httpclient的post方式请求,一直是报超时,url直接在浏览器中访问时却可以访问,不懂为什么??
于是我吧url改成百度,但是还是一直报超时,不清楚了,各位帮忙看下
代码如下
public class HttpClientUtils {
public static void main(String arg[]) throws Exception {
String url = "http://www.baidu.com/";
// getDoGetURL2(url,"utf-8");//测试ok
// getDoGetURL(url,"utf-8");//测试ok
getDoPostResponseDataByURL(url, null, "utf-8", true); // 测试ok
// WebUtils.doPost(url, null, 30000, 30000);
}
/**
 * 


 * 执行一个HTTP POST请求,返回请求响应的HTML
 * 


 * 
 * @param url
 *            请求的URL地址
 * @param params
 *            请求的查询参数,可以为null
 * @param charset
 *            字符集
 * @param pretty
 *            是否美化
 * @return 返回请求响应的HTML
 */
public static String getDoPostResponseDataByURL(String url,
Map params, String charset, boolean pretty) {
StringBuffer response = new StringBuffer();
HttpClient client = new HttpClient();
HttpMethod method = new PostMethod(url);
// 设置Http Post数据
if (params != null) {
HttpMethodParams p = new HttpMethodParams();
for (Map.Entry entry : params.entrySet()) {
p.setParameter(entry.getKey(), entry.getValue());
}
method.setParams(p);
}
try {
client.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_OK) {
// 读取为 InputStream,在网页内容数据量大时候推荐使用
BufferedReader reader = new BufferedReader(
new InputStreamReader(method.getResponseBodyAsStream(),
charset));
String line;
while ((line = reader.readLine()) != null) {
if (pretty)
response.append(line).append(
System.getProperty("line.separator"));
else
response.append(line);
}
reader.close();
}
} catch (IOException e) {
System.out.println("执行HTTP Post请求" + url + "时,发生异常!");
e.printStackTrace();
} finally {
method.releaseConnection();
}
System.out.println("--------------------" + response.toString());
return response.toString();
}
}
解决方案1:

httpclient jar,httpclient post,java httpclient,c# httpclient,android httpclient,httpclient下载,httpclient maven,http,httpclient post请求httpclient jar,httpclient post,java httpclient,c# httpclient,android httpclient,httpclient下载,httpclient maven,http,httpclient post请求

上一篇(jsp)分页列表,选择某一条记录跳到编辑页面后,怎样实现点击“返回‘按钮返回到这条记录所在的那个页面上?
下一篇(jsp)TOMCAT无法加载WEB-INF/lib下jar
明星图片
相关文章
《(jsp)httpclient post 请求一直超时,求解??》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)