Неожиданный код ответа 400 при использовании прокси OkHttp - PullRequest
1 голос
/ 19 января 2020

Кажется, что я получаю ошибку 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();

В последней строке указывается ошибка. Если бы кто-то мог помочь, это было бы здорово.

...