因此,我正在尝试让我的应用程序可与.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/}
感谢所有帮助!
答案 0 :(得分: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);