HTTP Request Submission Cookie

Source: Internet
Author: User

Package leadsservertest;


Import Org.apache.http.HttpResponse;
Import org.apache.http.client.HttpClient;
Import Org.apache.http.client.methods.HttpGet;
Import Org.apache.http.impl.client.BasicCookieStore;
Import Org.apache.http.impl.client.HttpClientBuilder;
Import Org.apache.http.impl.cookie.BasicClientCookie;
Import Org.apache.http.util.EntityUtils;
Import Org.junit.Test;

Import java.io.IOException;
Import Java.text.MessageFormat;
Import Java.util.concurrent.ExecutorService;
Import java.util.concurrent.Executors;

public class Performancetest {

@Test
public void Batchpost () throws IOException {
Executorservice Executorservice = Executors.newfixedthreadpool (20);
for (int i = n; i <; i++) {
int finali = i;
Executorservice.execute (New Runnable () {
@Override
public void Run () {
try {
6e296cdf-891b-40c7-bbbe-7b5f64e9893d
B3524207-7505-42af-a8d8-1e8da6e9ff70
String showid= "744DDBBD-4686-4C2B-874A-F63534C139B4";
/* if (finali%2==0) {
Showid= "B3524207-7505-42af-a8d8-1e8da6e9ff70";
}*/
Getandpostdata ("18300000" + string.valueof (Finali), showid);
} catch (IOException e) {
E.printstacktrace ();
}
}
});
}

System.in.read ();


}

void Getandpostdata (String phoneno,string showid) throws IOException {
Basiccookiestore Cookiestore = new Basiccookiestore ();
Basicclientcookie cookie = new Basicclientcookie ("Dealeradvshowid", showid);//"b3524207-7505-42af-a8d8-1e8da6e9ff70 ");
Cookie.setdomain (". dealeradv.autohome.com.cn");
Cookie.setpath ("/");

Cookiestore.addcookie (cookie);
HttpClient client = Httpclientbuilder.create (). Setdefaultcookiestore (Cookiestore). build ();

Final HttpGet request = new HttpGet ("Https://dealeradv.autohome.com.cn/Leads/getCreativeInfo");
HttpResponse response = Client.execute (request);
if (!outputresponseresult (response, Phoneno)) {
Return
System.out.println ("Get Exception:" +phoneno);
System.out.println (phoneno+ "------------------------------get Exception:" +entityutils.tostring ( Response.getentity ()));
Return
}

SYSTEM.OUT.PRINTLN ("Request get Phoneno:" +phoneno);

Submit data
String url = Messageformat.format ("https://dealeradv.autohome.com" +
". Cn/leads/index?car_series={0}&car_spec={1}&order_name={2}&order_phone_number={3}&city" +
"={4}&order_ip={5}", "3554", "27769", "Xu", Phoneno, "421100", "127.0.0.1");
HttpGet requestpostdata = new HttpGet (URL);
HttpResponse responsepost = Client.execute (Requestpostdata);
if (!outputresponseresult (Responsepost, Phoneno)) {
System.out.println (phoneno+ "------------------------------post Exception:" +entityutils.tostring ( Responsepost.getentity ()));
}

}

Boolean Outputresponseresult (HttpResponse response, String Phoneno) throws IOException {
if (Response.getstatusline (). Getstatuscode () = = 200) {
return true;
/*protocol Protocol = Json.parseobject (entityutils.tostring (Response.getentity ()), protocol.class);
if (Protocol.getreturncode () ==0) {
System.out.println (phoneno+ ", request successfully.) + entityutils.tostring (response.getentity ()));
return true;
}
else{
System.out.println (phoneno+ ", request faild.) + entityutils.tostring (response.getentity ()));
return false;
}*/
} else {
System.out.println (Phoneno + ", exception.");
return false;
}
}
}

HTTP Request Submission Cookie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.