我收到下一个错误:
线程中的异常" main" java.lang.NoClassDefFoundError: org / apache / commons / logging / LogFactory at org.apache.http.conn.ssl.DefaultHostnameVerifier。(DefaultHostnameVerifier.java:82) 在 org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955) 在Main.main(Main.java:87)引起: 抛出java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:381)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:338)at at java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 3更多
我使用intellij idea并导入了2个libs:httpclient-4.5.5.jar和httpcore-4.4.9.jar
我班上的所有馆藏:
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
代码示例:
String urlToSendRequest = Constants.HOST + Constants.URL;
String targetDomain = Constants.DOMAIN;
HttpClient httpClient = HttpClientBuilder.create().build();
HttpHost targetHost = new HttpHost(targetDomain, 80, "http");
HttpPost httpPost = new HttpPost(urlToSendRequest);
httpPost.addHeader("SENDCODE", "UTF-8");
//...
StringEntity entity = new StringEntity(Constants.MSG, "UTF-8");
entity.setContentType("application/xml");
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
我几乎可以肯定问题出在库导入上,但我不确定并且不知道如何修复它。
答案 0 :(得分:1)
请下载commons-logging jar文件并设置路径。
http://commons.apache.org/proper/commons-logging/download_logging.cgi
答案 1 :(得分:1)
请在项目中包含commons logging jar。 可以从here
下载同样来自Maven repository
答案 2 :(得分:1)
好像你缺少了公共 - 记录库。