81,094
社区成员
发帖
与我相关
我的任务
分享
private static final String url = "https://mall.shopee.com.my/api/v0/buyer/login/login_post/";
private static final String login_key = "NSQK.my";
private static final String login_type = "username";
private static final String password_hash = "9bfd6c1a1fa86b5d514d54486609da45e1885bb7810a8c350db72dbabf31d091";
private static final String captcha = "";
private static final String remember_me = "false";
public static CloseableHttpClient createSSLClientDefault(){
try {
SSLContext sslContext=new SSLContextBuilder().loadTrustMaterial(
null,new TrustStrategy() {
//信任所有
public boolean isTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
return true;
}
}).build();
SSLConnectionSocketFactory sslsf=new SSLConnectionSocketFactory(sslContext);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
}
return HttpClients.createDefault();
}
private static final String SOURCES =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
private static String randomStr() {
char[] text = new char[32];
for (int i = 0; i < 32; i++) {
text[i] = SOURCES.charAt(new Random().nextInt(SOURCES.length()));
}
return new String(text);
}
public static void main(String[] args) throws IOException {
CloseableHttpClient httpClient =createSSLClientDefault();
String csrftoken = randomStr();
HttpPost httppost2=new HttpPost(url);
httppost2.setHeader("referer","https://mall.shopee.com.my/");
httppost2.setHeader("x-csrftoken",csrftoken);
httppost2.setHeader("accept", "*/*");
httppost2.setHeader("accept-language", "zh-CN,zh;q=0.9,en;q=0.8");
httppost2.setHeader("content-type", "application/json");
httppost2.setHeader("origin", "https://mall.shopee.com.my");
httppost2.setHeader("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36");
httppost2.setHeader("x-api-source","pc");
httppost2.setHeader("x-requested-with","XMLHttpRequest");
httppost2.setHeader("Cookie","csrftoken="+csrftoken+"; REC_T_ID=fe753e26-2067-11e9-b249-5254000e999f; SPC_IA=-1; SPC_T_ID=\"RBKm/EFTD2X/6DounNIM1+eP/uhwOOKYJLIxwVUo4aUouVzZvhIBML/1DCpBVgA6LC4gmxlqcuZb0aoa1xfPBl6gnWa07RVjVYQELW9JfaA=\"; SPC_T_IV=\"NgBL1RygMKg5IpHWqBCGVg==\"");
JSONObject param = new JSONObject();
param.put("login_key",login_key);
param.put("login_type",login_type);
param.put("password_hash",password_hash);
param.put("captcha","");
param.put("remember_me",false);
StringEntity entity1 = new StringEntity(param.toString(),"utf-8");
httppost2.setEntity(entity1);
CloseableHttpResponse response=httpClient.execute(httppost2);
HttpEntity entity =response.getEntity();
String html=EntityUtils.toString(entity);
System.out.println(html);
//关闭连接
response.close();
httpClient.close();
}
截图命名返回200是成功啊