|
| 1 | + private String post(){ |
| 2 | + String userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36"; |
| 3 | + long timeStamp=Calendar.getInstance().getTimeInMillis(); |
| 4 | + String cookieStr="weimao_session=s%3AqMw2MW91Ja1BNVF0V2219smkXk7KAoR1.BriuuIb%2BZ2q2je%2FIMjmBw4gI7ibevI58pv7KcqD5R8g; Hm_lvt_c99fc61dc621e6b02c50ffce880b90b7=1504077167,1504158671,1505197068; Hm_lpvt_c99fc61dc621e6b02c50ffce880b90b7="+timeStamp/1000; |
| 5 | + CloseableHttpClient httpClient= HttpClients.custom() |
| 6 | + .setUserAgent(userAgent) |
| 7 | + .build(); |
| 8 | + |
| 9 | + HttpPost httpPost=new HttpPost(url); |
| 10 | + List<NameValuePair> params=new ArrayList<>(); |
| 11 | + params.add(new BasicNameValuePair("type","operation")); |
| 12 | + httpPost.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8)); |
| 13 | + |
| 14 | + List<Header> headerList=new ArrayList<>(); |
| 15 | + headerList.add(new BasicHeader("Cookie",cookieStr)); |
| 16 | + Header[] headers=new Header[headerList.size()]; |
| 17 | + for(int i=0;i<headerList.size();i++){ |
| 18 | + headers[i]=headerList.get(i); |
| 19 | + } |
| 20 | + |
| 21 | + httpPost.setHeaders(headers); |
| 22 | + try{ |
| 23 | + HttpResponse resp= httpClient.execute(httpPost); |
| 24 | + HttpEntity entity=null; |
| 25 | + if(resp!=null){ |
| 26 | + entity= resp.getEntity(); |
| 27 | + } |
| 28 | + |
| 29 | + if(entity!=null) { |
| 30 | + InputStreamReader inReader=new InputStreamReader(entity.getContent(),Consts.UTF_8); |
| 31 | + BufferedReader buf=new BufferedReader(inReader); |
| 32 | + StringBuilder sb = new StringBuilder(); |
| 33 | + |
| 34 | + String line=buf.readLine(); |
| 35 | + while(line!=null){ |
| 36 | + sb.append(line); |
| 37 | + line=buf.readLine(); |
| 38 | + } |
| 39 | + inReader.close(); |
| 40 | + |
| 41 | + return sb.toString(); |
| 42 | + } |
| 43 | + }catch(IOException ex){ |
| 44 | + ex.printStackTrace(); |
| 45 | + } |
| 46 | + |
| 47 | + return null; |
| 48 | + } |
0 commit comments