如题所述
HttpClient模æ请æ±å¦ä¸
HttpClient httpclient = new DefaultHttpClient(); //æå¼æµè§å¨
HttpPost httpPost = new HttpPost("www.xxx.xxx"); //è¾å ¥ç½å
List <NameValuePair> nvps = new ArrayList<NameValuePair>();
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 httpclient = new DefaultHttpClient(); //æå¼æµè§å¨
HttpPost httpPost = new HttpPost("www.xxx.xxx"); //è¾å ¥ç½å
List <NameValuePair> nvps = new ArrayList<NameValuePair>();
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å
纯æå·¥æå,请é纳å
温馨提示:答案为网友推荐,仅供参考
第1个回答 2015-02-07
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("");
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是怎么样的了。
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("");
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是怎么样的了。
第2个回答 2015-02-07
使用组件httpclient,网上有下载。