如何使用 Square 的 okHttp 设置不同数量的端口?
How do I set a different number of port using Square's okHttp?
我正在尝试将 okHttp 连接到 Web 服务,但端口不同,例如 10000。我的想法是在单元测试期间使用代理存根响应。尽管如此,没有足够的文档来制作这个库。事实上,我的实现是:
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(TIMEOUT_MS, TimeUnit.MILLISECONDS);
例如,与其他库如loopj,此功能是可能的:
httpClient.setProxy("localhost", 10000);
我正在使用这个版本:com.squareup.okhttp:okhttp:2.5.0
I'm trying to connect okHttp with a web service but with different port, for example, 10000
将您提供给 Request.Builder
的 URL 端口:
Request request = new Request.Builder()
.url("http://publicobject.com:10000/helloworld.txt")
.build();
My idea to stub the responses with a proxy during the unit tests.
对测试使用与生产中不同的 URL。
我正在尝试将 okHttp 连接到 Web 服务,但端口不同,例如 10000。我的想法是在单元测试期间使用代理存根响应。尽管如此,没有足够的文档来制作这个库。事实上,我的实现是:
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(TIMEOUT_MS, TimeUnit.MILLISECONDS);
例如,与其他库如loopj,此功能是可能的:
httpClient.setProxy("localhost", 10000);
我正在使用这个版本:com.squareup.okhttp:okhttp:2.5.0
I'm trying to connect okHttp with a web service but with different port, for example, 10000
将您提供给 Request.Builder
的 URL 端口:
Request request = new Request.Builder()
.url("http://publicobject.com:10000/helloworld.txt")
.build();
My idea to stub the responses with a proxy during the unit tests.
对测试使用与生产中不同的 URL。