2016-03-08 7 views
7

मैं Httpclient-4.5.2.jar और httpcore-4.4.4.jar HttpClient घटकों का उपयोग कर रहा हूं और मुझे त्रुटि नीचे मिल रही है।HTTP क्लाइंट "मुख्य" java.lang.No.SuchFieldError: org.apache.http.conn.ssl.SSLConnectionSocketFactory पर इंस्टॉलेशन। <clinit>

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

कृपया इस त्रुटि से छुटकारा पाने के लिए मेरी सहायता करें। मैं पोस्ट विधि में अनुरोध भेजने और जेसन प्रतिक्रिया प्राप्त करने की कोशिश कर रहा हूं।

+0

के संभावित डुप्लिकेट: http://stackoverflow.com/questions/32793830/error-while-trying-to-use-an-api-java-lang-nosuchfielderror-instance – HRgiger

+0

मैं लिंक से करने की कोशिश की है कि आपको दिया गया है। यह काम नहीं किया। जार फाइल संगतता की जांच करने का कोई तरीका है? कई पदों ने जार फ़ाइलों की संगतता की जांच की है। मुझे इन जार फ़ाइलों को httpcomponents-client-4.5.2-bin से मिला है। लेकिन यह भी काम नहीं किया। – dmaprasad

+0

क्षमा करें, मुझे नहीं पता लेकिन एक काम कर रहे ट्यूटोरियल को खोजने का प्रयास करें। यानी http://crunchify.com/how-to-create-restful-java-client-using-apache-httpclient-example/, जैसा कि आप यहां pom.xml httpcore और httpclient संस्करणों के साथ संगत में देखते हैं: 4.4-beta1 – HRgiger

उत्तर

2

मुझे आपके प्रश्न का उत्तर मिला और आपके संदर्भ के लिए पोस्टिंग मिली।

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

मेरे पास एक ही समस्या थी और यह समाधान मेरे लिए काम करता था। धन्यवाद। – Charitha

संबंधित मुद्दे