首页 > 解决方案 > 使用 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();

最后一行是错误的来源。如果有人可以提供帮助,那就太好了。

标签: javaproxyokhttp

解决方案


推荐阅读