3
回答
求教大神 帮我看看哪儿错了好吗?
华为云4核8G,高性能云服务器,免费试用   

@天体图 你好,帮我看看代码好吗:

String username = req.getParameter("username");
String pwd = req.getParameter("pwd");
try {
HttpClient httpclient = new DefaultHttpClient();
 
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager[] tm = { new MyX509TrustManager() };
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
// 创建SSLSocketFactory对象 
SSLSocketFactory ssf = new SSLSocketFactory(sslContext);  
 
   httpclient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, ssf));
 
   HttpPost post = new HttpPost("https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN");
    
   //Header cookie = new BasicHeader("Cookie", "ac=1,016,001; pt2gguin=o0503530115; RK=wD5qAuCPls; ptcz=2803611a23e59b710519c46b792d8df22cab01e413ca7b38e70465b1d6bc1df0; uin_cookie=1308300842; euin_cookie=70E0A746F5C21CF73A8B45D76B3098B3D71ECF8CF7C1D178; pgv_pvid=7669182920; cert=yAk4mLW8EJ02hefUt3BrpDoZSVPxpYmY");
   Header cookie = new BasicHeader("Cookie", "noticeLoginFlag=1");
   Header accept = new BasicHeader("Accept","*/*");
   Header enc = new BasicHeader("Accept-Encoding","gzip, deflate");
   Header lan = new BasicHeader("Accept-Language","zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3");
   Header contentType = new BasicHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
   Header agent = new BasicHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:38.0) Gecko/20100101 Firefox/38.0");
   Header referer = new BasicHeader("Referer","https://mp.weixin.qq.com/");
   Header host = new BasicHeader("Host","mp.weixin.qq.com");
    
   Header[] headers = {cookie,accept,enc,lan,contentType,agent,referer,host};
   post.setHeaders(headers);
 
   List<NameValuePair> nvps = new ArrayList<NameValuePair>();
   nvps.add(new BasicNameValuePair("username", username));
   nvps.add(new BasicNameValuePair("pwd", pwd));
   nvps.add(new BasicNameValuePair("f", "json"));
   nvps.add(new BasicNameValuePair("imgcode", ""));
   
   post.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
 
   // 发送请求
   HttpResponse response = httpclient.execute(post);
   // 输出返回值
   java.io.InputStream is = response.getEntity().getContent();
   BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
   String line = printAll(br);
   
   //printAll(br);
   br.close();
   String token = line.split("token=")[1].split("\"")[0]; 
   HttpGet get = new HttpGet("https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token="+token);
   
   response = httpclient.execute(get);
   // 输出返回值
   is = response.getEntity().getContent();
   br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
   //printAll(br); 
   //br.close();
   res.getWriter().write(line);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;

举报
魂牵
发帖于3年前 3回/312阅
顶部