java.net.UnknownHostException: Host is unresolved SOCKS proxy










0














I setup tor on a specific port and want to access the website through that port. The below code works perfectly in Android 7.0 but it gives below error in android 6.0. What may be the issue? The tor service successfully running at a specific port I am sending a request to.
Running sample code of this library (https://github.com/jehy/Tor-Onion-Proxy-Library)



Error




java.net.UnknownHostException: Host is unresolved: google.com
W/System.err: at java.net.Socket.connect(Socket.java:893)
W/System.err: at
cz.msebera.android.httpclient.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
W/System.err: at
com.example.nandan.sampletorproxyapp.MyConnectionSocketFactory.connectSocket(MyConnectionSocketFactory.java:33)
W/System.err: at
cz.msebera.android.httpclient.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
W/System.err: at
cz.msebera.android.httpclient.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
W/System.err: at
cz.msebera.android.httpclient.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
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: at
cz.msebera.android.httpclient.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
W/System.err: at
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.err: at
cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
W/System.err: at
com.example.nandan.sampletorproxyapp.MainActivity$TorTask.doInBackground(MainActivity.java:85)
W/System.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.err: at
java.util.concurrent.FutureTask.run(FutureTask.java:237) W/System.err:
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
W/System.err: at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:818)




Main Activity



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);











share|improve this question




























    0














    I setup tor on a specific port and want to access the website through that port. The below code works perfectly in Android 7.0 but it gives below error in android 6.0. What may be the issue? The tor service successfully running at a specific port I am sending a request to.
    Running sample code of this library (https://github.com/jehy/Tor-Onion-Proxy-Library)



    Error




    java.net.UnknownHostException: Host is unresolved: google.com
    W/System.err: at java.net.Socket.connect(Socket.java:893)
    W/System.err: at
    cz.msebera.android.httpclient.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
    W/System.err: at
    com.example.nandan.sampletorproxyapp.MyConnectionSocketFactory.connectSocket(MyConnectionSocketFactory.java:33)
    W/System.err: at
    cz.msebera.android.httpclient.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
    W/System.err: at
    cz.msebera.android.httpclient.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    W/System.err: at
    cz.msebera.android.httpclient.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    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: at
    cz.msebera.android.httpclient.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    W/System.err: at
    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.err: at
    cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    W/System.err: at
    com.example.nandan.sampletorproxyapp.MainActivity$TorTask.doInBackground(MainActivity.java:85)
    W/System.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.err: at
    java.util.concurrent.FutureTask.run(FutureTask.java:237) W/System.err:
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
    W/System.err: at
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    W/System.err: at
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    W/System.err: at java.lang.Thread.run(Thread.java:818)




    Main Activity



    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);











    share|improve this question


























      0












      0








      0







      I setup tor on a specific port and want to access the website through that port. The below code works perfectly in Android 7.0 but it gives below error in android 6.0. What may be the issue? The tor service successfully running at a specific port I am sending a request to.
      Running sample code of this library (https://github.com/jehy/Tor-Onion-Proxy-Library)



      Error




      java.net.UnknownHostException: Host is unresolved: google.com
      W/System.err: at java.net.Socket.connect(Socket.java:893)
      W/System.err: at
      cz.msebera.android.httpclient.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
      W/System.err: at
      com.example.nandan.sampletorproxyapp.MyConnectionSocketFactory.connectSocket(MyConnectionSocketFactory.java:33)
      W/System.err: at
      cz.msebera.android.httpclient.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
      W/System.err: at
      cz.msebera.android.httpclient.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
      W/System.err: at
      cz.msebera.android.httpclient.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
      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: at
      cz.msebera.android.httpclient.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
      W/System.err: at
      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.err: at
      cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
      W/System.err: at
      com.example.nandan.sampletorproxyapp.MainActivity$TorTask.doInBackground(MainActivity.java:85)
      W/System.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.err: at
      java.util.concurrent.FutureTask.run(FutureTask.java:237) W/System.err:
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
      W/System.err: at
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
      W/System.err: at
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
      W/System.err: at java.lang.Thread.run(Thread.java:818)




      Main Activity



      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);











      share|improve this question















      I setup tor on a specific port and want to access the website through that port. The below code works perfectly in Android 7.0 but it gives below error in android 6.0. What may be the issue? The tor service successfully running at a specific port I am sending a request to.
      Running sample code of this library (https://github.com/jehy/Tor-Onion-Proxy-Library)



      Error




      java.net.UnknownHostException: Host is unresolved: google.com
      W/System.err: at java.net.Socket.connect(Socket.java:893)
      W/System.err: at
      cz.msebera.android.httpclient.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
      W/System.err: at
      com.example.nandan.sampletorproxyapp.MyConnectionSocketFactory.connectSocket(MyConnectionSocketFactory.java:33)
      W/System.err: at
      cz.msebera.android.httpclient.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
      W/System.err: at
      cz.msebera.android.httpclient.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
      W/System.err: at
      cz.msebera.android.httpclient.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
      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: at
      cz.msebera.android.httpclient.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
      W/System.err: at
      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.err: at
      cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
      W/System.err: at
      com.example.nandan.sampletorproxyapp.MainActivity$TorTask.doInBackground(MainActivity.java:85)
      W/System.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.err: at
      java.util.concurrent.FutureTask.run(FutureTask.java:237) W/System.err:
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
      W/System.err: at
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
      W/System.err: at
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
      W/System.err: at java.lang.Thread.run(Thread.java:818)




      Main Activity



      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);








      android sockets proxy socks torsocks






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 17:33







      tarun14110

















      asked Nov 13 '18 at 3:06









      tarun14110tarun14110

      43321225




      43321225






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Try changing



          HttpGet httpGet = new HttpGet("http:google.co.in"); 


          to



          HttpGet httpGet = new HttpGet("http://google.co.in"); 


          or



          URI uri = new URIBuilder()
          .setScheme("http")
          .setHost("google.co.in")
          .build();
          HttpGet httpGet = new HttpGet(uri);


          updated - try this



          HttpHost target = new HttpHost("google.co.in", 80, "http");
          HttpGet request = new HttpGet("/");
          HttpResponse httpResponse = httpClient.execute(target, httpGet, context);


          If it don't work im not too sure. Maybe try this link hopefully this helps How to use HttpClientBuilder with Http proxy?






          share|improve this answer






















          • I was using HttpGet httpGet = new HttpGet("http://google.co.in");, Sorry, I did mistake why posting the question. The second one is also not working.
            – tarun14110
            Nov 13 '18 at 4:03










          • Updated my answer. Hopefully it helps
            – Mohammad C
            Nov 13 '18 at 12:29










          • Also if you print the port variable does it give you a valid port number or is null?
            – Mohammad C
            Nov 13 '18 at 12:35










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273194%2fjava-net-unknownhostexception-host-is-unresolved-socks-proxy%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Try changing



          HttpGet httpGet = new HttpGet("http:google.co.in"); 


          to



          HttpGet httpGet = new HttpGet("http://google.co.in"); 


          or



          URI uri = new URIBuilder()
          .setScheme("http")
          .setHost("google.co.in")
          .build();
          HttpGet httpGet = new HttpGet(uri);


          updated - try this



          HttpHost target = new HttpHost("google.co.in", 80, "http");
          HttpGet request = new HttpGet("/");
          HttpResponse httpResponse = httpClient.execute(target, httpGet, context);


          If it don't work im not too sure. Maybe try this link hopefully this helps How to use HttpClientBuilder with Http proxy?






          share|improve this answer






















          • I was using HttpGet httpGet = new HttpGet("http://google.co.in");, Sorry, I did mistake why posting the question. The second one is also not working.
            – tarun14110
            Nov 13 '18 at 4:03










          • Updated my answer. Hopefully it helps
            – Mohammad C
            Nov 13 '18 at 12:29










          • Also if you print the port variable does it give you a valid port number or is null?
            – Mohammad C
            Nov 13 '18 at 12:35















          0














          Try changing



          HttpGet httpGet = new HttpGet("http:google.co.in"); 


          to



          HttpGet httpGet = new HttpGet("http://google.co.in"); 


          or



          URI uri = new URIBuilder()
          .setScheme("http")
          .setHost("google.co.in")
          .build();
          HttpGet httpGet = new HttpGet(uri);


          updated - try this



          HttpHost target = new HttpHost("google.co.in", 80, "http");
          HttpGet request = new HttpGet("/");
          HttpResponse httpResponse = httpClient.execute(target, httpGet, context);


          If it don't work im not too sure. Maybe try this link hopefully this helps How to use HttpClientBuilder with Http proxy?






          share|improve this answer






















          • I was using HttpGet httpGet = new HttpGet("http://google.co.in");, Sorry, I did mistake why posting the question. The second one is also not working.
            – tarun14110
            Nov 13 '18 at 4:03










          • Updated my answer. Hopefully it helps
            – Mohammad C
            Nov 13 '18 at 12:29










          • Also if you print the port variable does it give you a valid port number or is null?
            – Mohammad C
            Nov 13 '18 at 12:35













          0












          0








          0






          Try changing



          HttpGet httpGet = new HttpGet("http:google.co.in"); 


          to



          HttpGet httpGet = new HttpGet("http://google.co.in"); 


          or



          URI uri = new URIBuilder()
          .setScheme("http")
          .setHost("google.co.in")
          .build();
          HttpGet httpGet = new HttpGet(uri);


          updated - try this



          HttpHost target = new HttpHost("google.co.in", 80, "http");
          HttpGet request = new HttpGet("/");
          HttpResponse httpResponse = httpClient.execute(target, httpGet, context);


          If it don't work im not too sure. Maybe try this link hopefully this helps How to use HttpClientBuilder with Http proxy?






          share|improve this answer














          Try changing



          HttpGet httpGet = new HttpGet("http:google.co.in"); 


          to



          HttpGet httpGet = new HttpGet("http://google.co.in"); 


          or



          URI uri = new URIBuilder()
          .setScheme("http")
          .setHost("google.co.in")
          .build();
          HttpGet httpGet = new HttpGet(uri);


          updated - try this



          HttpHost target = new HttpHost("google.co.in", 80, "http");
          HttpGet request = new HttpGet("/");
          HttpResponse httpResponse = httpClient.execute(target, httpGet, context);


          If it don't work im not too sure. Maybe try this link hopefully this helps How to use HttpClientBuilder with Http proxy?







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 12:25

























          answered Nov 13 '18 at 3:13









          Mohammad CMohammad C

          1,1831312




          1,1831312











          • I was using HttpGet httpGet = new HttpGet("http://google.co.in");, Sorry, I did mistake why posting the question. The second one is also not working.
            – tarun14110
            Nov 13 '18 at 4:03










          • Updated my answer. Hopefully it helps
            – Mohammad C
            Nov 13 '18 at 12:29










          • Also if you print the port variable does it give you a valid port number or is null?
            – Mohammad C
            Nov 13 '18 at 12:35
















          • I was using HttpGet httpGet = new HttpGet("http://google.co.in");, Sorry, I did mistake why posting the question. The second one is also not working.
            – tarun14110
            Nov 13 '18 at 4:03










          • Updated my answer. Hopefully it helps
            – Mohammad C
            Nov 13 '18 at 12:29










          • Also if you print the port variable does it give you a valid port number or is null?
            – Mohammad C
            Nov 13 '18 at 12:35















          I was using HttpGet httpGet = new HttpGet("http://google.co.in");, Sorry, I did mistake why posting the question. The second one is also not working.
          – tarun14110
          Nov 13 '18 at 4:03




          I was using HttpGet httpGet = new HttpGet("http://google.co.in");, Sorry, I did mistake why posting the question. The second one is also not working.
          – tarun14110
          Nov 13 '18 at 4:03












          Updated my answer. Hopefully it helps
          – Mohammad C
          Nov 13 '18 at 12:29




          Updated my answer. Hopefully it helps
          – Mohammad C
          Nov 13 '18 at 12:29












          Also if you print the port variable does it give you a valid port number or is null?
          – Mohammad C
          Nov 13 '18 at 12:35




          Also if you print the port variable does it give you a valid port number or is null?
          – Mohammad C
          Nov 13 '18 at 12:35

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273194%2fjava-net-unknownhostexception-host-is-unresolved-socks-proxy%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto