자바 서로 다른 국가 ip 시 뮬 레이 션 요청 실현
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
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.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
public class HttpTest {
public static void main(String[] args) throws IOException {
String url = "http://clk.trkmobi.net/call/v2/ad/click";
//data=URLEncoder.encode(data,"utf8");
Map map = new HashMap<>();
map.put("recommend_id","5800001");
map.put("ads_id","47476944");
map.put("aff_id","1004081");
map.put("ak_id","15511");
map.put("aff_sub","IIvIszV-aNbE_5_QPY7iKwX-WPDnDBDZMJ90Bvpq9blFR8K9bLkhigGujdlrWhmUlYbyNewj6MVtPmL3B2mbuzSAsP_l-4kKH3xBHdP_3mfRSOLS_3V5kyL1Qkxjd-dM");
map.put("aff_sub2","2b9f8ef9-af50-4e16-973a-fe7d76cf39fb");
map.put("aff_sub3","1d4f10d-7878-4a15-b33f-ad711d48058c");
send(url,map,"utf-8");
}
/**
* HTTP
* @param url
* @param map
* @param encoding
* @return
* @throws ParseException
* @throws IOException
*/
public static String send(String url, Map map, String encoding) throws IOException {
CloseableHttpResponse response = null;
String body = "";
// httpclient
CloseableHttpClient client = HttpClients.custom().setRetryHandler(new DefaultHttpRequestRetryHandler(0,false)).build();
// post
HttpPost httpPost = new HttpPost(url);
//
List nvps = new ArrayList();
if(map!=null){
for (Map.Entry entry : map.entrySet()) {
nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
}
//
httpPost.setEntity(new UrlEncodedFormEntity(nvps, encoding));
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(10000).setSocketTimeout(10000).build();
httpPost.setConfig(requestConfig);
httpPost.addHeader("x-forwarded-for","210.125.84.15"); // ip
//httpPost.addHeader("x-forwarded-for","169.235.24.133"); // ip
//httpPost.addHeader("x-forwarded-for","116.21.94.96"); // ip
//
System.out.println(" :"+url);
System.out.println(" :"+nvps.toString());
// , ( )
response = client.execute(httpPost);
//
HttpEntity entity = response.getEntity();
if (entity != null) {
// String
body = EntityUtils.toString(entity, encoding);
}
EntityUtils.consume(entity);
//
response.close();
// log.info(" :"+body);
System.out.println(" :"+JsonUtil.object2JsonString(body)+" response:"+response.getStatusLine());
return body;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.