Java는 HTTP 보내기 요청을 시뮬레이션합니다. 첫 번째는 httpurlconnection입니다. 두 번째는 httppclient를 사용하여 게시물 요청을 시뮬레이션하는 것입니다.
예제 코드 :
패키지 테스트; import java.util.arraylist; import java.util.hashmap; import java.util.list; import java.util.map; import java.util.map.entry; import java.util.concurrent.executorservice; import java.util.concurrent.concutors; org.apache.http.httpentity; import org.apache.http.namevaluepair; import org.apache.http.client.config.requestconfig; import org.apache.http.client.entity.urlencodedformentity; org.apache.http.client.methods.closeablehttpresponse; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.closeablehttpclient; import org.apache.http.impl.client.htpclients; org.apache.http.message.basicnamevaluepair; import org.apache.http.util.entityutils;/** java 시뮬레이션 테스트 멀티 스레드 테스트 http 요청*@author wdh**/public eplicethreadtest runtable {string, 대상, 대상; url, 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 (getParamstr;) void setparamstparamst (map <string). {this.paramstr = paramstr;}@attrestridepublic void run () {// http 요청 구현 메소드 closeablehttpclient httpclient = httpclients.createdefault (); requestConfig.custom (). SetConnectionRequestTimeout (10000) .SetConnectTimeout (10000) .SetSocketTimeout (10000) .Build (); CloseBlayHttPresponse reponship = null; try {list <namevaluepair> params = sethttpnamevalues (paramstr); httpentity httpentity = new urlencodedformentity (params, "utf-8"); post.setentity (httpentity); post.setconfig (config); 응답 = httpclient.execute (post); httpentity entity = response.getentity =; EntityUtils.tostring (entity); System.out.println ( "content :" + content);} catch (예외 e) {e.printstacktrace ();}} 개인 목록 <NamesValuePair> sethttpnameValues (map <string, object> parammap) {list <namevaluepair> params = new arraylist <namevaluepair>; for (enther <string, object> entry : parammap.entryset ()) {params.add (new BasicNameValuePair (enther.getKey (), enther.getValue (). toString ())); } return params;} public static void main (string [] args) {// Java Tool Class ExecutorService Pool = Executors.newCachedThreadpool (); for (int i = 0; i <2; i ++) {// 두 스레드 string url = "xxxx"; map <string, 객체> gethttpparamstr (); servicethreadtest (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을 지원 해주셔서 감사합니다.