JavaはHTTPの送信リクエストをシミュレートします。 1つ目は、httpurlconnectionを送信します郵送リクエストです。 2つ目は、httppclientを使用して投稿リクエストをシミュレートすることです。
例コード:
パッケージテスト; java.util.arraylist; import java.util.hashmap; import java.util.list; import java.util.map.entry; import java.util.concurrent.executorservice; Import java.util.util.concurrent.current.executors; org.apache.http.httpentity; Import org.apache.http.namevaluepair; Import org.apache.http.client.config.RequestConfig; Import org.apache.http.client.entity.urlencodedformentity; Import org.apache.http.client.methods.closeablehttpresponse; Import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.closablehttpclient; Import org.apache.httpclient; Import.Client.httpclient; org.apache.http.message.basicnamevaluepair; Import org.apache.http.util.entityutils;/** Javaシミュレーションテストマルチスレッドテストhttpリクエスト*@author wdh**/public class serviceethreadtest実装慣習map <string、object> paramstr){super(); this.url = url; this.paramstr = paramstr;} public string geturl(){return url;} public void seturl(string url){this.url = url;} public map <string、object> getparamstr(){return param paramstr;}@overridepublic void run(){// http要求実装メソッドcloseablehttpclient = httpclient = httpclient.createdefault(); httppost post = new httppost(url); requestConfig config = RequestConfig.Custom()。setConnectionRequestTimeout(10000).setConnectTimeout(10000).Setsockettimeout(10000).Build(); closeablehttpresponse Response = null; try {list <namevaluepair> params = sethttpnamevalues(paramstr); httpentity httpentity = new urlencodedformentity(params、 "utf-8"); post.setEntity(httpentity); post.setconfig(config); response = httpclient.execute(post); httpentity entity = response.getentity(); entityutils.tostring(entity); system.out.println( "content:" + content);} catch(expect(e.printstacktrace();}} private list <namevaluepair> sethttpnamevalues(map <string、object> parammap){namevaluepair> params = new Arririst <new Arrylist <; for(entry <string、object> entry:parammap.entryset()){params.add(new BasicNameValuePair(entry.getKey()、entry.getValue()。toString()); } return params;} public static void main(string [] args){// Java Toolクラスでスレッドプールを使用します。 serviceethreadtest(url、paramstr));}} public static map <string、object> gethttpparamstr(){map <string、object> param = new hashmap <string、object>(); param.put( "apiversion"、1); param.put( "appversion"、 "3.6.2"); return param;}}}}上記は、JavaシミュレーションマルチスレッドHTTPリクエストについて共有されているすべてのコンテンツです。 wulin.comへのご支援ありがとうございます。