GET请求
public String doGet(String url) throws IOException{
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url);
String text = "";
try {
client.executeMethod(get);
text = get.getResponseBodyAsString();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
get.releaseConnection();
}
return text;
}
POST请求
public String doPost(String url){
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
post.setParameter("OrderCode", "");
post.setParameter("ShipperCode", "SF");
post.setParameter("LogisticCode", "118650888018");
String restString = "";
try {
client.executeMethod(post);
restString = post.getResponseBodyAsString();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return restString;
}