qq_25546483 2015-03-06 09:05 采纳率: 0%
浏览 2393

想做一个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 + "\r\n");
            }
            System.out.print(strHtml.toString());


        }catch(Exception e){
            e.printStackTrace();
        }finally {
            if (httpurlconnection != null)
                httpurlconnection.disconnect();   
        }
    }




}

  • 写回答

1条回答 默认 最新

  • ChrisyehGone 2015-08-14 07:52
    关注

    一般都是去官方照demo、sdk、和说明文档

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。