Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

json - HTTPClient "main" java.lang.NoSuchFieldError: INSTANCE at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>

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)

My source code as follows.

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();

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...