HTTPClient "main" java.lang.NoSuchFieldError: org.apache.http.conn.ssl.SSLConnectionSocket
Posted
技术标签:
【中文标题】HTTPClient "main" java.lang.NoSuchFieldError: org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit> 处的实例【英文标题】:HTTPClient "main" java.lang.NoSuchFieldError: INSTANCE at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit> 【发布时间】:2016-03-08 13:06:58 【问题描述】:我正在使用 Httpclient-4.5.2.jar 和 httpcore-4.4.4.jar HttpClient 组件,但出现以下错误。
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 响应。
【问题讨论】:
可能重复:***.com/questions/32793830/… 我从您提供的链接中尝试过。它没有用。有没有办法检查jar文件的兼容性?许多帖子说检查 jar 文件的兼容性。我从 httpcomponents-client-4.5.2-bin 获得了这些 jar 文件。但它也没有用。 对不起,我不知道,但尝试找到一个工作教程。即 crunchify.com/… ,正如您在 pom.xml 中看到的那样 httpcore 和 httpclient 与以下版本兼容:4.4-beta1 当第 3 方依赖项引入旧版本的 apache 的 http 核心库时,我遇到了同样的错误。检查你的依赖树 如何检查依赖树? 【参考方案1】:我找到了我的问题的答案并发布了供您参考。
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.SSLConnectionSocket的主要内容,如果未能解决你的问题,请参考以下文章
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogF
Exception in thread "main" java.sql.SQLRecoverableException: 无法从套接字读取更多的数据,哪里出问题