Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example;
- // import the required classes
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.Response;
- import java.io.IOException;
- import java.net.InetSocketAddress;
- import java.net.Proxy;
- public class Main {
- String run(String url) throws IOException {
- // define your proxy details
- String proxyHost = "140.238.247.9";
- int proxyPort = 8100;
- // create a proxy object and pass in the necessary details
- Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
- // create a OkHttpClient builder instance and configure it to use the proxy
- OkHttpClient client = new OkHttpClient.Builder()
- .proxy(proxy)
- .build();
- // create a request with the provided URL
- Request request = new Request.Builder()
- .url(url)
- .build();
- // execute the request and obtain the response
- try (Response response = client.newCall(request).execute()) {
- // return the response body as a string
- return response.body().string();
- }
- }
- public static void main(String[] args) throws IOException {
- // create an instance of the Main class
- Main example = new Main();
- // make a GET request to the specified URL and print the response
- String response = example.run("https://httpbin.io/ip");
- System.out.println(response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement