// 查询手机号
HttpClient client=new HttpClient();
client.getHostConfiguration().setProxy("192.168.1.235", 808);
client.getHostConfiguration().setHost("haoma.imobile.com.cn", 80, "http");
//HttpMethod method=getPostMethod(); //用PostMethod方法实现
HttpMethod method=getGetMethod();
try {
client.executeMethod(method);
System.out.println(method.getStatusLine());
String response =
new String(method.getResponseBodyAsString().getBytes("utf-8"));
//打印返回的信息
System.out.println(response);
method.releaseConnection();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 使用GET方式提交数据; * @return
*/
private static HttpMethod getGetMethod(){
return new GetMethod("index.php?mob=1350514");
}
/**
* 使用POST方式提交数据
* @return
*/
private static HttpMethod getPostMethod(){
PostMethod post = new PostMethod("/index.php");
NameValuePair simcard = new NameValuePair("mob","1330227");
post.setRequestBody(new NameValuePair[] { simcard});
return post;
}
说明导入包:
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;