您的位置:首页 > 编程语言 > Java开发

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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: