HttpClient模拟请求如下
HttpClient httpclient = new DefaultHttpClient(); //打开浏览器
HttpPost httpPost = new HttpPost("www.xxx.xxx"); //输入网址
Listnvps = new ArrayList ();
nvps.add(new BasicNameValuePair("userName","123"));
nvps.add(new BasicNameValuePair("password","123")); //封装表单
httpPost.setEntity(new UrlEncodedFormEntity(nvps,"utf-8")); //将参数传入post方法中
HttpResponse response = httpclient.execute(httpPost); //执行post
HttpEntity entity = response.getEntity(); //获取响应数据
String result = EntityUtils.toString(entity); //将响应数据转成字符串
需要导入jar包
纯手工打字,请采纳哈
httpclient就行了,给你个取IP的例子好了
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
public class IPHelper {
public String getSourceText(String ip) throws IOException {
String text = null;
HttpClient client = new HttpClient();
client.getParams().setContentCharset("GBK");
PostMethod post = new PostMethod("http://www.ip138.com/ips8.asp");
NameValuePair[] data = { new NameValuePair("action", "2"),
new NameValuePair("ip", ip) };
post.setRequestBody(data);
client.executeMethod(post);
text = post.getResponseBodyAsString();
post.releaseConnection();
return text;
}
public static void main(String[] args) throws IOException {
IPHelper h=new IPHelper();
System.out.println(h.getSourceText("192.169.0.1"));
}
}
这个是Post的,还有Get的,看你的form是怎么样的了。