httpserver
This commit is contained in:
parent
397b67a704
commit
a328a51b03
|
|
@ -43,8 +43,10 @@ public class Init {
|
||||||
public static void init(Context context) {
|
public static void init(Context context) {
|
||||||
get().app = ((Application) context);
|
get().app = ((Application) context);
|
||||||
SpiderDebug.log("自定義爬蟲代碼載入成功!" + "1");
|
SpiderDebug.log("自定義爬蟲代碼載入成功!" + "1");
|
||||||
|
execute(() -> {
|
||||||
ProxyServer.INSTANCE.stop();
|
ProxyServer.INSTANCE.stop();
|
||||||
ProxyServer.INSTANCE.start();
|
ProxyServer.INSTANCE.start();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void execute(Runnable runnable) {
|
public static void execute(Runnable runnable) {
|
||||||
|
|
@ -63,7 +65,8 @@ public class Init {
|
||||||
try {
|
try {
|
||||||
Activity activity = Init.getActivity();
|
Activity activity = Init.getActivity();
|
||||||
if (activity == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
|
if (activity == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
|
||||||
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) return;
|
if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
|
||||||
|
return;
|
||||||
activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 9999);
|
activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 9999);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ object ProxyServer {
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
|
|
||||||
|
do {
|
||||||
try {
|
try {
|
||||||
httpServer = AdvancedHttpServer(port)
|
httpServer = AdvancedHttpServer(port)
|
||||||
httpServer?.addRoutes("/") { _, response ->
|
httpServer?.addRoutes("/") { _, response ->
|
||||||
|
|
@ -47,13 +47,14 @@ object ProxyServer {
|
||||||
httpServer?.start()
|
httpServer?.start()
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
SpiderDebug.log("start server e:" + e.message)
|
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
SpiderDebug.log("启动服务出错:" + e.message)
|
||||||
|
|
||||||
|
port++
|
||||||
httpServer?.stop()
|
httpServer?.stop()
|
||||||
}
|
}
|
||||||
|
} while (port < 20000)
|
||||||
SpiderDebug.log("Server start on $port")
|
SpiderDebug.log("启动服务 on $port")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +102,9 @@ object ProxyServer {
|
||||||
|
|
||||||
|
|
||||||
response.setHeader("Connection", "keep-alive")
|
response.setHeader("Connection", "keep-alive")
|
||||||
response.setHeader("Content-Length", (finalEndPoint - startPoint + 1).toString())
|
response.setHeader(
|
||||||
|
"Content-Length", (finalEndPoint - startPoint + 1).toString()
|
||||||
|
)
|
||||||
response.setHeader(
|
response.setHeader(
|
||||||
"Content-Range", "bytes $startPoint-$finalEndPoint/$contentLength"
|
"Content-Range", "bytes $startPoint-$finalEndPoint/$contentLength"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
4111cbdc5007a7e0510c84e4162e5ad9
|
f857aaa917fac3bce9f407d7a8262ba7
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"spider": "https://gh.llkk.cc/https://raw.githubusercontent.com/lushunming/AndroidCatVodSpider/multiThreadNew/jar/custom_spider.jar;md5;4111cbdc5007a7e0510c84e4162e5ad9",
|
"spider": "https://gh.llkk.cc/https://raw.githubusercontent.com/lushunming/AndroidCatVodSpider/multiThreadNew/jar/custom_spider.jar;md5;f857aaa917fac3bce9f407d7a8262ba7",
|
||||||
"lives": [
|
"lives": [
|
||||||
{
|
{
|
||||||
"name": "电视直播",
|
"name": "电视直播",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue