OkHttp proxy settings

后端 未结 3 2045
情歌与酒
情歌与酒 2021-02-07 00:14

I have to setup a proxy to send a JSON using POST, using proxyHost and proxyPort.

public static final MediaType JSON = MediaType.parse(\"application/json; charse         


        
3条回答
  •  失恋的感觉
    2021-02-07 00:32

    okhttp version:3.11.0. SOCKS proxy example

    String hostname = "localhost"/*127.0.0.1*/;
    int port = 1080;
    Proxy proxy = new Proxy(Proxy.Type.SOCKS,
            new InetSocketAddress(hostname, port));
    
    OkHttpClient client = new OkHttpClient.Builder()
            .proxy(proxy)
            .build();
    

提交回复
热议问题