post 请求 博客分类: java java
程序员文章站
2024-03-06 13:28:37
...
public static void trustEveryone() {
try {
HttpsURLConnection
.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname,
SSLSession session) {
return true;
}
});
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context
.getSocketFactory());
} catch (Exception e) {
// e.printStackTrace();
}
}
/**
* @param good_url 商品URl
* @return 返回值是商品的评价数量
*/
public static String getEv_num(String good_url){
try {
String id=good_url.split("/")[6].split(".html")[0];
String url="http://www.sfbest.com/comments/ajaxPl/";
URL baseurl = new URL(url);
trustEveryone();
org.jsoup.Connection conn = HttpConnection.connect(baseurl);
conn.timeout(10000);
conn.header("accept", "application/json, text/javascript, */*; q=0.01");
conn.header("Accept-Encoding", "gzip, deflate");
conn.header("Accept-Language", "zh-CN,zh;q=0.8");
conn.header("connection", "Keep-Alive");
conn.header("Content-Length", "35");
conn.header("Content-Type", "application/x-www-form-urlencoded");
conn.header("Cookie","siteid=SF_CURRENT_SITE; provinceid=2; cityid=52; areaid=500; " +
"townid=0; bdshare_firstime=1516961354705; _SF_USER_HASH_=a86c5eca7ca4db3e; " +
"_SF_AUTH_HASH_=4ddeb3771b7991c3; _ems_visitor=1417598425.329643289;" +
" _da_z=24490488.1517799775.5.2.ccn=(referral)|csr=sfbest.com|cct=/html/products/244/1300243033.html|cmd=referral; " +
"__xsptplus130=130.2.1517799883.1517800202.4%234%7C%7C%7C%7C%7C%23%23-ts5ran1n4TdkcvHp5-Y6QZKQeUDDbjr%23;" +
" _da_a=24490488.20180126180902624745.1516961343.1517799775.1517810037.6;" +
" __utma=24490488.1119885806.1517465621.1517796317.1517812872.3; " +
"__utmb=24490488.4.9.1517813131564; __utmc=24490488; " +
"__utmz=24490488.1517465621.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);" +
" _ems_session=1417598425.561290200;" +
" _sf_tj_cc=ymfz0gxvaau1516961342392.1516961342.1517799774.1517810036.6.13.1517813531; " +
"Hm_lvt_cceda50ef06cbaf44bdeaabe2470efee=1516961342,1517394409,1517794523;" +
" Hm_lpvt_cceda50ef06cbaf44bdeaabe2470efee=1517813531;" +
" history=a%3A10%3A%7Bi%3A0%3Bi%3A251937%3Bi%3A1%3Bi%3A257431%3Bi%3A2%3Bi%3A58179%3Bi%3A3%3Bi%3A264699%3Bi%3A4%3Bi%3A264575%3Bi%3A5%3Bi%3A233885%3Bi%3A6%3Bi%3A271517%3Bi%3A7%3Bi%3A245643%3Bi%3A8%3Bi%3A279119%3Bi%3A9%3Bi%3A279811%3B%7D; " +
"_da_b=24490488.13.10.1517810037;" +
"Hm_lvt_56b4bab8080250772f08703b41839413=1516961340,1517394409,1517794521;" +
"Hm_lpvt_56b4bab8080250772f08703b41839413="+new Date().getTime());
conn.header("Host","www.sfbest.com");
conn.header("Origin","http://www.sfbest.com");
conn.header("Referer",good_url);
conn.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
conn.header("X-Requested-With", "XMLHttpRequest");
conn.data("pid","282387");
conn.data("page","1");
conn.data("pageNum","10");
conn.data("type","0");
conn.ignoreContentType(true);
//conn.execute();
Document parse = conn.post();
Thread.sleep(1000);
String str=parse.text();
System.err.println(id);
System.err.println(str);
System.err.println(new Date().getTime());
return null;
} catch (Exception e) {
// TODO: handle e xception
}
return null;
}
public static void main(String[] args) {
String url="http://www.sfbest.com/comments/ajaxPl/";
String param="http://www.sfbest.com/html/products/280/4200279811.html";
try {
System.out.println(getEv_num(param));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
上一篇: JDBC 使用说明(流程、架构、编程)
下一篇: C++17 std::shared_mutex的替代方案boost::shared_mutex 博客分类: C/C++ C++17boost
推荐阅读
-
post 请求 博客分类: java java
-
java获取当前时间的时间戳 博客分类: java java时间戳
-
谈谈Java利用原始HttpURLConnection发送POST数据
-
java去除图片水印的解决办法 博客分类: java java
-
java ascii转中文(ascii转utf-8)清测好用 博客分类: java javaasciiutf-8
-
java细节之list删除 博客分类: JAVA java
-
java三大范式 博客分类: java java
-
java下载图片到本地实例 博客分类: java java
-
java模拟http的Get/Post请求,并设置ip与port代理的方法
-
Java使用HttpClient实现Post请求实例