Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.IOException: Unexpected response code for CONNECT: 400

Tags:

java

okhttp

I am using Okhttp client to get the OAuth 2.0 token based on a Rest API.

When I deploy it over Weblogic 12c its showing the error 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

like image 343
Jawad-Dev Avatar asked Mar 09 '26 16:03

Jawad-Dev


1 Answers

CONNECT is the HTTP method OkHttp uses to build an HTTPS connection through a proxy server. It uses either the proxy server configured in your OkHttpClient, or the one the JVM prefers via its ProxySelector feature.

A 400 response from CONNECT implies the proxy doesn't like the CONNECT request. You probably need to disable the proxy altogether (pass Proxy.NO_PROXY to OkHttpClient.Builder) or fix it to accept this call.

like image 155
Jesse Wilson Avatar answered Mar 11 '26 06:03

Jesse Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!