java - 使用 OkHttp 代理时出现意外的响应代码 400
问题描述
每当我尝试使用代理运行我的程序时,我似乎都会收到 OkHttp 错误。这是我得到的错误:
java.io.IOException: Unexpected response code for CONNECT: 400
at okhttp3.internal.connection.RealConnection.createTunnel(RealConnection.kt:454)
at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.kt:233)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:174)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:238)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:111)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:79)
at okhttp3.internal.connection.Transmitter.newExchange$okhttp(Transmitter.kt:163)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:35)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:82)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:71)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.kt:194)
at okhttp3.RealCall.execute(RealCall.kt:67)
at JustTal.Client.<init>(Client.java:37)
at JustTal.Main.main(Main.java:55)
以下是错误附近的行:
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyDetails.split(":")[0], Integer.parseInt(proxyDetails.split(":")[1])));
builder.proxy(proxy);
Request request = new Request.Builder().url("https://website.com").build();
Response r = client.newCall(request).execute();
最后一行是错误的来源。如果有人可以提供帮助,那就太好了。
解决方案
推荐阅读
- android - 为什么在 EditText 的开头有额外的空间
- python - 如何使用 Python 从本地文件创建数据 url?
- javascript - 如何在浏览器/标签关闭时发送 API 请求?
- reactjs - React Bootstrap Table KeyField 与两个主键
- c - 使用 malloc 为 C 指针赋值,无需变量初始化
- sql - 如何计算雅典娜表中每列的空值百分比
- android - 在调试器工具窗口中看不到协程选项卡
- complexity-theory - 我们可以说 2x+1 = o(-5x^2+2)
- python - 使用 datatable 读取大尺寸 csv 文件的错误信息
- arrays - Powershell 从 CSV 文件中的所有列构建所有可能组合的数组