web-dev-qa-db-ja.com

HTTPClient "main" Java.lang.NoSuchFieldError:org.Apache.http.conn.ssl.SSLConnectionSocketFactory。<clinit>のインスタンス

Httpclient-4.5.2.jarおよびhttpcore-4.4.4.jarHttpClientコンポーネントを使用していますが、以下のエラーが発生します。

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レスポンスを取得しようとしています。

9
dmaprasad

私の質問に対する答えを見つけ、参考のために投稿しました。

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