Paimiya
Paimiya

Reputation: 105

How to send http request to onion server?

I had built a tor hidden service on Android phone. The web page of hidden service can be displayed in another Android phone through Tor browser.

Now I would like to create a client APP to send http request to the hidden service. But I have no idea for it.

Any suggestion? Thanks!

Upvotes: 0

Views: 1429

Answers (1)

Paimiya
Paimiya

Reputation: 105

I found the solution using OkHttp

InetSocketAddress proxyAddr = new InetSocketAddress("127.0.0.1", 9050);
Proxy proxyTor = new Proxy(Proxy.Type.SOCKS, proxyAddr);

OkHttpClient.Builder builder = new OkHttpClient.Builder().proxy(proxyTor).connectTimeout(30, TimeUnit.SECONDS);
OkHttpClient client = builder.build();
Request request = new Request.Builder().url(address).build();

try (Response response = client.newCall(request).execute()) {
    result = response.body().string();
} catch (Exception e) {
    e.printStackTrace();
}

Upvotes: 1

Related Questions