问题描述
- 想做一个java b站的第三方登录,请问有什么比较方便的jar包可以引用?
-
如题,还是说只能用httpurlconnection?然后我用wireshark试图抓account.bilibili.com/login的数据包,结果死活抓不到post的包。。。感觉如果没有post包的话没办法进行数据分析。。。就没办法继续写下去了。。。由于是第一次设计,所以可能思路会有点问题,如果有做过类似程序的前辈感谢给出一点点建议。。。。谢谢!import java.net.URL; import java.net.HttpURLConnection; import java.io.InputStream; import java.io.BufferedInputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.BufferedReader; public class Answer { private static final String FrontPageURL = "http://www.bilibili.com"; private static final String LoginPageURL = "http://account.bilibili.com/login"; private static final String AnswerPageURL = "http://www.bilibili.com/account/invite_quiz"; public static void main(String argv[]) throws Exception { Login(); } public static void Login() { URL url = null; HttpURLConnection httpurlconnection = null; // 就是这里,如果抓不到post数据包,就不知道b站的login格式是什么样的!! String strPost = ""; try{ url = new URL(LoginPageURL); httpurlconnection = (HttpURLConnection) url.openConnection(); httpurlconnection.setRequestProperty("User-Agent", "Internet Explorer"); httpurlconnection.setRequestProperty("Host", "account.bilibili.com"); httpurlconnection.setFollowRedirects(true); httpurlconnection.setInstanceFollowRedirects(true); httpurlconnection.setDoOutput(true); httpurlconnection.setDoInput(true); httpurlconnection.setUseCaches(false); httpurlconnection.setAllowUserInteraction(false); httpurlconnection.setRequestMethod("POST"); httpurlconnection.addRequestProperty("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-silverlight, */*"); httpurlconnection.setRequestProperty("Accept-Language", "zh-cn"); httpurlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpurlconnection.setRequestProperty("Accept-Encoding", "gzip, deflate"); httpurlconnection.setRequestProperty("Content-Length", strPost.length()+ ""); httpurlconnection.setRequestProperty("Connection", "Keep-Alive"); httpurlconnection.setRequestProperty("Cache-Control", "no-cache"); httpurlconnection.getOutputStream().write(strPost.getBytes()); httpurlconnection.getOutputStream().flush(); httpurlconnection.getOutputStream().close(); httpurlconnection.connect(); httpurlconnection.disconnect(); InputStream urlStream = httpurlconnection.getInputStream(); BufferedInputStream buff = new BufferedInputStream(urlStream); Reader r = new InputStreamReader(buff, "utf8"); BufferedReader br = new BufferedReader(r); StringBuffer strHtml = new StringBuffer(""); String strLine = null; while ((strLine = br.readLine()) != null){ strHtml.append(strLine + "rn"); } System.out.print(strHtml.toString()); }catch(Exception e){ e.printStackTrace(); }finally { if (httpurlconnection != null) httpurlconnection.disconnect(); } } }
解决方案
一般都是去官方照demo、sdk、和说明文档
时间: 2024-10-31 22:13:26