java 根据url请求别的项目方法
2014-09-05 11:48
351 查看
String userId = request.getParameter("userId");
HttpClient http = new HttpClient();
String returnJson="";
try {
PostMethod method = new PostMethod(url);
method.addParameter("userId", userId); //传递参数
http.executeMethod(method);
returnJson = method.getResponseBodyAsString(); //返回结果
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Charset", "UTF-8");
PrintWriter out = response.getWriter();
out.print(returnJson);
out.flush();
out.close();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpClient http = new HttpClient();
String returnJson="";
try {
PostMethod method = new PostMethod(url);
method.addParameter("userId", userId); //传递参数
http.executeMethod(method);
returnJson = method.getResponseBodyAsString(); //返回结果
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Charset", "UTF-8");
PrintWriter out = response.getWriter();
out.print(returnJson);
out.flush();
out.close();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
相关文章推荐
- 解决用Spring框架的javaWeb项目post请求方法乱码的问题
- java 向指定 URL 发送Get\Post方法的请求
- Java获取此次请求URL以及服务器根路径的方法
- Java获取此次请求URL以及服务器根路径的方法
- java 向指定URL发送GET、POST方法的请求
- MTK平台根据特定项目定义一个C++,java中用到的宏方法
- 服务器根据URL以及data信息与微信服务器交互的post请求方法(之一)
- Java如何实现URL带请求参数(get/post)及得到get和post请求url和参数列表的方法
- java实现:http协议get和post方法的url参数请求响应及交互
- Java根据URL连接请求JSON数据解析代码
- 向指定URL发送POST或GET请求工具类-JAVA项目
- 【转】解决Fiddler不能监听Java HttpURLConnection请求的方法
- 百度地图API 云存储·LBS.云 跨域问题解决方法——通过java.net.URLConnection发送HTTP请求
- 解决Fiddler不能监听Java HttpURLConnection请求的方法
- 【JAVA】JAVA程序根据url请求网站HTML页面
- 向指定URL发送GET方法的请求(java)
- Java获取此次请求URL以及服务器根路径的方法
- JAVA根据请求拼接URL地址
- Java根据URL连接请求JSON数据解析代码