使用HttpClient获得手机归属地

现在写这个程序,不能将有效的信息摘出来,以后摘出来会补上

package test3;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
/**
 * 用HttpClient通过网页的回复获得号码的归属地
 * 最好的方式是写一个正则表达式把回来的信息摘出来
 * 正在努力写,以后写出补上
 * @author wangyj
 */

public class SimpleHttpClient {
    public static void main(String[] args) throws IOException
    {
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost("www.ip138.com", 8080, "http");
        HttpMethod method = getPostMethod();//使用POST方式提交数据
        HttpMethod method2 = getGetMethod();//使用GET方式提交数据
        client.executeMethod(method2);
       //获得返回数据流页面
       String response =   new String(method2.getResponseBodyAsString().getBytes("8859_1"));
       //将获得的数据流页面打印出来
       System.out.println(response);
       //释放链接
        method.releaseConnection();
    }
    /**
     * 使用GET方式提交数据
   * @return
     */
    private static HttpMethod getGetMethod(){
        return new GetMethod("/search.asp?action=mobile&mobile=13811844766");
    }
    /**
     * 使用POST方式提交数据
   * @return
     */
    private static HttpMethod getPostMethod(){
        PostMethod post = new PostMethod("/search.asp");
        NameValuePair action = new NameValuePair("action","mobile");
        NameValuePair mobile = new NameValuePair("mobile","13888888888");
        post.setRequestBody(new NameValuePair[] { action});
        post.setRequestBody(new NameValuePair[] { mobile});
        return post;
    }
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值