Java يحاكي طلبات إرسال HTTP. الأول هو httpurlconnection إرسال طلبات البريد. والثاني هو استخدام httppclient لمحاكاة طلبات النشر.
رمز المثال:
اختبار الحزمة ؛ استيراد java.util.arraylist ؛ استيراد java.util.hashmap ؛ استيراد java.util.list ؛ استيراد java.util.map ؛ import java.util.map.entry ؛ import java.util.concurrent.Executorservice ؛ org.apache.http.httpentity ؛ import org.apache.http.namevaluepair ؛ import org.apache.http.client.config.requestconfig ؛ import org.apache.http.client.entity.urlencodformentity ؛ org.apache.http.client.methods.closablehttpresponse ؛ import org.apache.http.client.methods.httppost ؛ import org.apache.http.impl.client.closablehttpclient org.apache.http.message.basicnamevaluepair ؛ import org.apache.http.util.entityUtils ؛/** java simulation test multithered url urdr ؛ request requistr*string order ؛ url ، map <string ، object> paramstr) {super () ؛ this.url = url ؛ this.paramstr = paramstr ؛} السلسلة العامة geturl () {return url ؛} public void seturl (string url) {this.url = url ؛ {this.paramstr = paramstr ؛}@overridepublic void run () {// http method method electionation abeliablehttpclient httpclient = httpclients.createdefault () ؛ httppost post = new httppost (url) ؛ requestConfig.custom (). httpentity httpentity = جديد urlencodedformentity (params ، "utf-8") ؛ post.setentity (httpentity) ؛ post.setConfig (config) ؛ response = httpclient.execute (post) ؛ httpentity ictity = response.getentity () ؛ entityUtils.ToString (intity) ؛ system.out.println ("المحتوى:" + content) ؛} catch (استثناء e) {E.PrintStackTrace () ؛}} القائمة الخاصة <MameValuePair> sethttpnamevalues (map <string> parammap) {list <namevaluepair> params = new لـ (إدخال <string ، Object> الإدخال: parammap.entryset ()) {params.add (new BasicNameValuePair (entrate.getKey () ، intradvalue (). tostring ())) ؛ } return params ؛} public static void main (string [] args) {// استخدم pool thread pool في java tool class pool = executors.newcachedthreadpool () ؛ for (int i = 0 ؛ i <2 ؛ i ++) {// open اثنين ServiceThReadTest (url ، paramstr)) ؛}} خريطة ثابتة عامة <سلسلة ، كائن> gethttpparamstr () {map <string ، object> param = new hashmap <string ، object> () ؛ param.put ("apiversion" ، 1)ما سبق هو كل المحتوى المشترك حول طلبات HTTP متعددة الخيوط Java. شكرا لدعمكم ل wulin.com.