直接在浏览器地址栏中输入http://www.sms10000.com:8080/MT?id=1,可以正常看到返回值
可是如果在程序中,返回值却是空,请帮忙解决,程序如果修改可以得到和浏览器方法一样的结果或者根本不行.
public class test1 { public static void main(String[] args) throws HttpException, IOException {
HttpClient httpClient = new HttpClient(); String url = "http://www.sms10000.com:8080/MT";
PostMethod postMethod = new PostMethod(url);
NameValuePair[] data = { new NameValuePair("id", "123"),
new NameValuePair("passwd", "123") };
postMethod.setRequestBody(data);
int statusCode = httpClient.executeMethod(postMethod);
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY ||
statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
Header locationHeader = postMethod.getResponseHeader("location");
String location = null;
if (locationHeader != null) {
location = locationHeader.getValue();
System.out.println("The page was redirected to:" + location);
} else {
System.err.println("Location field value is null.");
}
return;
}
byte[] responseBody = postMethod.getResponseBody();
String s="";
if (responseBody != null) {
s = new String(responseBody).trim();
}
System.out.println("s="+s);
}
}
可是如果在程序中,返回值却是空,请帮忙解决,程序如果修改可以得到和浏览器方法一样的结果或者根本不行.
public class test1 { public static void main(String[] args) throws HttpException, IOException {
HttpClient httpClient = new HttpClient(); String url = "http://www.sms10000.com:8080/MT";
PostMethod postMethod = new PostMethod(url);
NameValuePair[] data = { new NameValuePair("id", "123"),
new NameValuePair("passwd", "123") };
postMethod.setRequestBody(data);
int statusCode = httpClient.executeMethod(postMethod);
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY ||
statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
Header locationHeader = postMethod.getResponseHeader("location");
String location = null;
if (locationHeader != null) {
location = locationHeader.getValue();
System.out.println("The page was redirected to:" + location);
} else {
System.err.println("Location field value is null.");
}
return;
}
byte[] responseBody = postMethod.getResponseBody();
String s="";
if (responseBody != null) {
s = new String(responseBody).trim();
}
System.out.println("s="+s);
}
}
楼主【bingki】截止到2008-07-30 14:14:00的历史汇总数据(不包括此帖):
发帖的总数量:12 发帖的总分数:220 每贴平均分数:18
回帖的总数量:17 得分贴总数量:5 回帖的得分率:29%
结贴的总数量:12 结贴的总分数:220
无满意结贴数:4 无满意结贴分:90
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:33.33 % 无满意结分率:40.91 %
敬礼!
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=bingki