Я настраиваю tor для определенного порта и хочу получить доступ к веб-сайту через этот порт.Приведенный ниже код прекрасно работает в Android 7.0, но в Android 6.0 выдает ошибку ниже.В чем может быть проблема?Служба tor успешно работает на определенном порту, на который я отправляю запрос.Пример кода этой библиотеки (https://github.com/jehy/Tor-Onion-Proxy-Library)
Ошибка
java.net.UnknownHostException: Хост не разрешен: google.com W / System.err: at java.net.Socket.connect (Socket.java:893) W / System.err: на cz.msebera.android.httpclient.conn.socket.PlainConnectionSocketFactory.connectSocket (PlainConnectionSocketFactory.java:74) W / System.err: на com.example.Nandan.cz.msebera.android.httpclient.impl.conn.PoolingHttpClientConnectionManager.connect (PoolingHttpClientConnectionManager.java:353) W / System.err: в cz.msebera.android.httplient.ExouenExe) W / System.err: at cz.msebera.android.httpclient.impl.execchain.MainClientExec.execute (MainClientExec.java:236) W / System.err: at cz.msebera.android.httpclient.impl.execchain.ProtocolExec.execute (ProtocolExec.java:184) W / System.err: at cz.msebera.android.httpclient.impl.execchain.RetryExec.execute (RetryExec.Java: 88) W / System.err: на cz.msebera.android.httpclient.impl.execchain.RedirectExec.execute (RedirectExec.java:110) W / System.err: на cz.msebera.android.httpclient.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:184) W / System.err: at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:82) W / System.er.msebera.android.httpclient.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:55) W / System.err: в com.example.nandan.sampletorproxyapp.MainActivity $ TorTask.doInBackground (MainActivity.java: 85).err: at com.example.nandan.sampletorproxyapp.MainActivity $ TorTask.doInBackground (MainActivity.java:60) W / System.err: at android.os.AsyncTask $ 2.call (AsyncTask.java:295) W / System.ошибка: на java.util.concurrent.FutureTask.run (FutureTask.java:237) W / System.err: на android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java:234) W / System.err: на java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java: 1113) W / System.err: в java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:588) W / System.err: в java.lang.Thread.run (Thread.java:818)
Основная активность
HttpClient httpClient = getNewHttpClient();
int port = onionProxyManager.getIPv4LocalHostSocksPort();
InetSocketAddress socksaddr = new InetSocketAddress("127.0.0.1", port);
HttpClientContext context = HttpClientContext.create();
context.setAttribute("socks.address", socksaddr);
HttpGet httpGet = new HttpGet("http://google.co.in");
HttpResponse httpResponse = httpClient.execute(httpGet, context); // GETTING ERROR HERE
static class FakeDnsResolver implements DnsResolver {
@Override
public InetAddress[] resolve(String host) throws UnknownHostException {
return new InetAddress[] { InetAddress.getByAddress(new byte[] { 1, 1, 1, 1 }) };
}
}
public HttpClient getNewHttpClient() {
Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", new MyConnectionSocketFactory())
.build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg,new FakeDnsResolver());
return HttpClients.custom()
.setConnectionManager(cm)
.build();
}
MyConnectionSocketFactory.java
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Socket;
import cz.msebera.android.httpclient.HttpHost;
import cz.msebera.android.httpclient.conn.socket.PlainConnectionSocketFactory;
import cz.msebera.android.httpclient.protocol.HttpContext;
public class MyConnectionSocketFactory extends PlainConnectionSocketFactory {
@Override
public Socket createSocket(final HttpContext context) {
InetSocketAddress socksaddr = (InetSocketAddress) context.getAttribute("socks.address");
Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr);
return new Socket(proxy);
}
@Override
public Socket connectSocket(
int connectTimeout,
Socket socket,
final HttpHost host,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpContext context) throws IOException{
InetSocketAddress unresolvedRemote = InetSocketAddress
.createUnresolved(host.getHostName(), remoteAddress.getPort());
return super.connectSocket(connectTimeout, socket, host, unresolvedRemote, localAddress, context);
}
}