[英]java.io.IOException: Unexpected response code for CONNECT: 400
I am using Okhttp client to get the OAuth 2.0 token based on a Rest API.我正在使用 Okhttp 客户端获取基于 Rest API 的 OAuth 2.0 令牌。
When I deploy it over Weblogic 12c its showing the error java.io.IOException: Unexpected response code for CONNECT: 400当我通过 Weblogic 12c 部署它时,它显示错误java.io.IOException: Unexpected response code for CONNECT: 400
I have tried to change the implementation and header method methods in different styles might be my request is failing because I am providing wrong credentials but nothing changed.我试图以不同的样式更改实现和标头方法方法,可能是我的请求失败了,因为我提供了错误的凭据,但没有任何改变。
Can anybody suggest what I am doing wrong in my code?有人可以建议我在代码中做错了什么吗?
Client Code客户代码
public String Post (String url, String json) throws IOException {
Response response = null;
try {
logger.info("FMS WEBSERVICE LOG >>> Posting method...");
RequestBody body = RequestBody.create(JSON, json);
logger.info("FMS WEBSERVICE LOG >>> body: " + body);
Request request = new Request.Builder().url(url).post(body).build();
logger.info("FMS WEBSERVICE LOG >>> request: " + request);
response = client.newCall(request).execute();
logger.info("FMS WEBSERVICE LOG >>> returning: " + response.toString());
}
catch (Exception e) {
logger.info("FMS WEBSERVICE LOG >>> exception in WebServiceClient: " + e);
}
return response.body().string();
}
@GET
@Path("/fundTransfer")
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
public String soapCaller() throws IOException, JSONException {
logger.info("FMS WEBSERVICE LOG >>> Inside the client method");
String json = new StringBuilder()
.append("{")
.append("\"grant_type\":\"client_credentials\",")
.append("\"client_id\":\"0146b9a4-7e99-4c83-8e9e-6049cfec55da\",")
.append("\"client_secret\":\"nY3oL5xQ3bJ8yT3nC1nV5bY4mY6eW7yP1nY6dS6rQ2nE5iR0rM\",")
.append("\"scope\":\"ABLApis\"")
.append("}").toString();
logger.info("FMS WEBSERVICE LOG >>> JSON >>> " + json.toString());
String response = Post("https://221.120.211.69:443/abl-api/uat/oauth2/token", json);
logger.info("FMS WEBSERVICE LOG >>> response >>> " + response);
return response;
}
I am using postman to hit the GET Request with this URL: http:///FMS_WEB_SERVICES/fmsServices/fundTransfer我正在使用邮递员通过以下 URL 发送 GET 请求:http:///FMS_WEB_SERVICES/fmsServices/fundTransfer
CONNECT
is the HTTP method OkHttp uses to build an HTTPS connection through a proxy server. CONNECT
是 OkHttp 用来通过代理服务器建立 HTTPS 连接的 HTTP 方法。 It uses either the proxy server configured in your OkHttpClient, or the one the JVM prefers via its ProxySelector feature.它使用 OkHttpClient 中配置的代理服务器,或者 JVM 通过其 ProxySelector 功能首选的代理服务器。
A 400 response from CONNECT implies the proxy doesn't like the CONNECT request.来自 CONNECT 的 400 响应意味着代理不喜欢 CONNECT 请求。 You probably need to disable the proxy altogether (pass Proxy.NO_PROXY to OkHttpClient.Builder) or fix it to accept this call.您可能需要完全禁用代理(将 Proxy.NO_PROXY 传递给 OkHttpClient.Builder)或修复它以接受此调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.