HTTPClient“main” java.lang.NoSuchFieldError:在org.apache.http.conn.ssl.SSLConnectionSocketFactory上的INSTANCE。< clinit> [英] HTTPClient "main" java.lang.NoSuchFieldError: INSTANCE at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>

查看:1328
本文介绍了HTTPClient“main” java.lang.NoSuchFieldError:在org.apache.http.conn.ssl.SSLConnectionSocketFactory上的INSTANCE。< clinit>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Httpclient-4.5.2.jar和httpcore-4.4.4.jar HttpClient组件,我收到以下错误。

I'm using Httpclient-4.5.2.jar and httpcore-4.4.4.jar HttpClient components and I'm getting below error.

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)

我的源代码如下。

try {
        System.out.println("came to try catch");
        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpPost request = new HttpPost("https://bizz.mobilezz.lk/apicall/loanprepaidapi/v1");
        StringEntity params =new StringEntity("{\"mobile\":\"776037285\",\"path\":\"IVV\",\"loanAmount\":\"200000\"}");
        request.addHeader("content-type", "application/json");
        request.addHeader("Authorization", "Bearer casmk34233mlacscmaacsac");

        request.addHeader("Accept", "application/json");        
        request.setEntity(params);
        HttpResponse response = httpClient.execute(request);
        System.out.println("response is :"+response.getStatusLine());

    } catch (Exception e) {
        e.printStackTrace();

请帮我摆脱这个错误。我正在尝试在post方法中发送请求并获得json响应。

Please assist me to get rid of this error. I'm trying to send request in post method and get json response.

推荐答案

我找到了一个问题的答案并发布了您的参考。

I found an answer to my question and posting for your reference.

HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(
                "https://bizz.mobilezz.lk/apicall/loanprepaidapi/v1");

        JSONObject json = new JSONObject();
        StringEntity params = new StringEntity("{\"msisdn\":\"" + mobile
                + "\",\"channel\":\"SDD\"}");

        new StringEntity(json.toString());
        post.addHeader("Host", "mife.dialog.lk");
        post.addHeader("content-type", "application/json");
        post.addHeader("Authorization", "Bearer " + access_token);
        post.addHeader("Accept", "application/json");

        // System.out.println("status code is:" + status);
        post.setEntity(params);
        HttpResponse response = client.execute(post);
        int status = response.getStatusLine().getStatusCode();
        System.out.println("status code is :" + status);
        resCode = Integer.toString(status);
        if (status != 401) {
            if (status != 409) {
                BufferedReader rd = new BufferedReader(
                        new InputStreamReader(response.getEntity()
                                .getContent()));
                String response1 = readAll(rd);
                System.out.println(response1);
                JSONObject obj = new JSONObject(response1);
                resCode = obj.getString("resCode");
                resDesc = obj.getString("resDesc");
                System.out.println(resCode);
                System.out.println(resDesc);
            }
        }
        System.out.println("reason code is :" + resCode);

这篇关于HTTPClient“main” java.lang.NoSuchFieldError:在org.apache.http.conn.ssl.SSLConnectionSocketFactory上的INSTANCE。&lt; clinit&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆