修复B站登陆监测403问题
This commit is contained in:
parent
8145a1c313
commit
c04ada610f
@ -17,7 +17,7 @@ public class BiliBiliUtils {
|
||||
public synchronized static JSONObject http_get(String url) {
|
||||
try {
|
||||
// Log.i("调用url = "+url);
|
||||
HttpURLConnection connection = getBiliHttpGet(url, getCookie());
|
||||
HttpsURLConnection connection = getBiliHttpGet(url, getCookie());
|
||||
BufferedInputStream stream = new BufferedInputStream(connection.getInputStream());
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[1024];
|
||||
@ -135,7 +135,7 @@ public class BiliBiliUtils {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public static HttpURLConnection getBiliHttpGet(String url, String cookie) throws IOException {
|
||||
public static HttpsURLConnection getBiliHttpGet(String url, String cookie) throws IOException {
|
||||
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
@ -143,7 +143,7 @@ public class BiliBiliUtils {
|
||||
}
|
||||
oldBiliBiliHttpTime = System.currentTimeMillis();
|
||||
}
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
setConnection(cookie, connection);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.setConnectTimeout(5000);
|
||||
@ -154,7 +154,7 @@ public class BiliBiliUtils {
|
||||
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||
connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8");
|
||||
connection.setRequestProperty("Cache-Control", "max-age=0");
|
||||
connection.setRequestProperty("Referer", ".bilibili.com");
|
||||
//connection.setRequestProperty("Referer", ".bilibili.com");
|
||||
connection.setRequestProperty("Connection", "keep-alive");
|
||||
connection.setRequestProperty("Upgrade-Insecure-Requests", "1");
|
||||
connection.setRequestProperty("Cookie", cookie);
|
||||
|
@ -68,6 +68,7 @@ public class BiliLogin {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BiliLogin login = new BiliLogin();
|
||||
login.testLogin();
|
||||
boolean testLogin = login.testLogin();
|
||||
System.out.println("testLogin = " + testLogin);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user