package com.httpclient.demo;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class CheckPhone {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
CheckPhone cp=new CheckPhone();
//cp.get("18312345678");
cp.post("18312345678");
}
/**
* 通过get方式获取
* @param mobileCode 手机号码
* @throws Exception
*/
public void get(String mobileCode) throws Exception{
HttpClient httpclient = new HttpClient();
GetMethod getMethod = new GetMethod(
"http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode="
+ mobileCode + "&userID=");
int statuCode=httpclient.executeMethod(getMethod);
System.out.println("响应状态码:"+statuCode);
String result= getMethod.getResponseBodyAsString();
System.out.println("响应的结果:"+result);
}
/**
* 通过post方式获取
* @param mobileCode
* @throws Exception
*/
public void post(String mobileCode) throws Exception{
HttpClient httpclient = new HttpClient();
PostMethod postMethod = new PostMethod("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo");
postMethod.setParameter("mobileCode", mobileCode);
postMethod.setParameter("userID", "");
int statuCode=httpclient.executeMethod(postMethod);
System.out.println("响应状态码:"+statuCode);
String result= postMethod.getResponseBodyAsString();
System.out.println("响应的结果:"+result);
}
}
通过Httpclient的get,post获取手机号码信息
最新推荐文章于 2024-07-15 12:30:13 发布