0

所以,我试图让我的应用程序与 .onion 域一起使用,但我得到的只是响应的 405 错误。我已经尝试了一切,当我尝试http://check.torproject.org它说它已连接时,我的代码似乎可以工作。

https://github.com/guardianproject/NetCipher

我的 gradle 包含这些依赖项。

compile 'info.guardianproject.netcipher:netcipher:2.0.0-alpha1'
compile 'info.guardianproject.netcipher:netcipher-okhttp3:2.0.0-alpha1'
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'org.apache.httpcomponents:httpcore:4.4.1'

我正在运行此代码来启动 orbot 并将应用程序连接到它。

OrbotHelper.get(activity).statusTimeout(60000).addStatusCallback(new StatusCallback(){
    @Override
    public void onEnabled(Intent intent){
        new StrongBuild();
    }

    @Override
    public void onStarting(){
    }

    @Override
    public void onStopping(){
    }

    @Override
    public void onDisabled(){
    }

    @Override
    public void onStatusTimeout(){
    }

    @Override
    public void onNotYetInstalled(){
    }
}).init();

这是 StrongBuild 文件。

import android.util.Log;

import javax.net.ssl.TrustManager;

import info.guardianproject.netcipher.client.StrongBuilder;
import info.guardianproject.netcipher.client.StrongOkHttpClientBuilder;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class StrongBuild implements StrongBuilder.Callback<OkHttpClient> {

public StrongBuild(){
    Log.e("info", "Starting Strong Builder");
    try{
        StrongOkHttpClientBuilder.
                forMaxSecurity(activity).
                //withTrustManagers(new TrustManager[] { new MyTrustManager() }).
                withTorValidation().
                withBestProxy().
                build(StrongBuild.this);

    }catch(Exception e){
        e.printStackTrace();
        Log.e("info", "ERROR");
    }
}

@Override
public void onConnected(final OkHttpClient okHttpClient){
    Log.e("info" , "CONNECTED Strong Builder");

    new Thread(new Runnable(){
        @Override
        public void run(){
            try{
                Request request = new Request.Builder().url("http://******.onion/").build();
                Response response = okHttpClient.newCall(request).execute();

                Log.e("info", "RESPONSE: "+response.toString());
                Log.e("info", response.body().string());
            }catch(Exception e){
                e.printStackTrace();
                Log.e("info", "ERROR - ATTEMPTING CONNECTION TO ONION DOMAIN");
            }
        }
    }).start();
}

@Override
public void onConnectionException(Exception e){
    Log.e("info" , "Exception");
}

@Override
public void onTimeout(){
    Log.e("info" , "Timeout");
}

@Override
public void onInvalid(){
    Log.e("info" , "Invalid");
}
}

堆栈跟踪:

RESPONSE: Response{protocol=http/1.0, code=405, message=Method Not Allowed, url=http://********.onion/}

感谢所有帮助!

4

1 回答 1

0

好的,我发现了这个问题,我会为其他想知道的人发布答案!

改变这个:

StrongOkHttpClientBuilder.
            forMaxSecurity(activity).
            //withTrustManagers(new TrustManager[] { new MyTrustManager() }).
            withTorValidation().
            withBestProxy().
            build(StrongBuild.this);

对此:

StrongOkHttpClientBuilder.
            forMaxSecurity(activity).
            withTrustManagers(new TrustManager[] { new MyTrustManager() }).
            withTorValidation().
            withSocksProxy().
            withHttpProxy().
            build(StrongBuild.this);
于 2018-09-28T08:53:14.977 回答