现在写这个程序,不能将有效的信息摘出来,以后摘出来会补上
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;
}
}