| package com.cloud.day1; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import Org.apache.commons.httpclient.HttpMethod; import Org.apache.commons.httpclient.NameValuePair; import Org.apache.commons.httpclient.methods.GetMethod; import Org.apache.commons.httpclient.methods.PostMethod; /** * According to the POST request, the place where the query number belongs */ Public class Demo4 { /** * @param args * @throws HttpException * @throws IOException */ Public static void main (string[] args) throws HttpException, IOException { HttpClient httpclient = new httpclient (); Httpclient.gethostconfiguration (). Sethost ("www.114best.com", "n", "http"); HttpMethod method = Postmethod (); Httpclient.executemethod (method); System.out.println ("1:" +method.getstatusline ()); String response = new string (method.getresponsebodyasstring ()); System.out.println ("2:" +response); Method.releaseconnection (); } /** * Data submitted by Get method * @return HttpMethod */ @SuppressWarnings ("unused") private static HttpMethod GetMethod () { return New GetMethod ("/simcard.php?simcard=1330227"); } /** * Submit data using POST method * @return HttpMethod */ private static HttpMethod Postmethod () { Here according to the URL above stitching query parameters Postmethod post = new postmethod ("/dh/114.aspx"); Namevaluepair w = new namevaluepair ("W", "18225896837"); Post.setrequestbody (new namevaluepair[]{w}); return post; } } |