简体   繁体   English

Android上的HTTP代理

[英]Http proxy on Android

I try to create http proxy within my Android app. 我尝试在我的Android应用程序中创建http代理。 I use this code inside onCreate() method: 我在onCreate()方法中使用以下代码:

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.2.2", 8080));
HttpURLConnection e = (HttpURLConnection)url.openConnection(proxy);
e.setReadTimeout(10000);
e.setConnectTimeout(15000);
e.setRequestMethod("GET");
e.connect();

My app throw exceptions: 我的应用抛出异常:

I/O exception: java.net.SocketTimeoutException: failed to connect to /10.0.2.2 (port 8080) after 15000ms

Then I tried to create http Proxy server using LittleProxy : 然后,我尝试使用LittleProxy创建http代理服务器:

compile group: 'org.littleshoot', name: 'littleproxy', version: '1.0.0-beta7'


public class MyHttpProxyServer {
    org.littleshoot.proxy.HttpProxyServer server;
    public MyHttpProxyServer(){
        server = DefaultHttpProxyServer.bootstrap().withAddress(InetSocketAddress.createUnresolved("10.0.2.2", 8080)).start();
    }
}

I added this lines to gradle.build file, bc gradle didn't want build app otherwise: 我将此行添加到gradle.build文件中,否则bc gradle不想构建应用程序:

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}

And here my emulator refused to start app: 在这里,我的模拟器拒绝启动应用程序:

Failure [INSTALL_FAILED_NO_MATCHING_ABIS]

When I comment all LittleProxy import - emulator again works fine. 当我评论所有LittleProxy导入-模拟器再次正常运行时。 So I doubt is LittleProxy compatible with Android? 所以我怀疑LittleProxy是否与Android兼容? On the other hand I have seen people had used it previously 另一方面,我看到人们以前使用过它

change the version to be 1.0.0 将版本更改为1.0.0

compile group: 'org.littleshoot', name: 'littleproxy', version: '1.0.0' 编译组:“ org.littleshoot”,名称:“ littleproxy”,版本:“ 1.0.0”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM