要求将数据库中获取的一条数据上报成功,用java模拟 post请求?求大神给点例子啊或者思路啊。解决必采纳 60
展开全部
import org.apache.commons.httpclient.methods.PostMethod;
String url="";
PostMethod pm = new PostMethod(url);
pm.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=GBK");
pm.setRequestHeader(....);
.....//设置请求头信息
pm.addParameter(String,Object);
....//设置参数
this.executeMethod(pm);//发送请求
String rt = toString(pm.getResponseBodyAsStream(),"GBK");//解析响应
String url="";
PostMethod pm = new PostMethod(url);
pm.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=GBK");
pm.setRequestHeader(....);
.....//设置请求头信息
pm.addParameter(String,Object);
....//设置参数
this.executeMethod(pm);//发送请求
String rt = toString(pm.getResponseBodyAsStream(),"GBK");//解析响应
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询