使用httpClient4.5的问题 求大家来看看..不知道怎么解决

博主在使用HttpClient4.5抓取网页时遇到了与安卓系统内置HTTP客户端冲突的问题,表现为无法找到静态字段及方法调用失败等。该文详细记录了错误日志并探讨可能的原因。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我导入了httpClient4.5来抓取网页 运行报以下错误 好像是jar包的问题 以前没遇到过 不知该如何处理 是因为和安卓jar包中的http冲突了吗? 


 DexOpt: couldn't find static field Lorg/apache/http/impl/client/DefaultConnectionKeepAliveStrategy;.INSTANCE
 VFY: unable to resolve static field 3329 (INSTANCE) in Lorg/apache/http/impl/client/DefaultConnectionKeepAliveStrategy;

 VFY: replacing opcode 0x62 at 0x012b
 DexOpt: couldn't find static field Lorg/apache/http/impl/client/DefaultUserTokenHandler;.INSTANCE
 VFY: unable to resolve static field 3367 (INSTANCE) in Lorg/apache/http/impl/client/DefaultUserTokenHandler;
 VFY: replacing opcode 0x62 at 0x0149
 Could not find method org.apache.http.util.VersionInfo.getUserAgent, referenced from method org.apache.http.impl.client.HttpClientBuilder.build
 VFY: unable to resolve static method 13444: Lorg/apache/http/util/VersionInfo;.getUserAgent (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/String;
VFY: replacing opcode 0x71 at 0x0169
 Could not find method org.apache.http.protocol.RequestUserAgent.<init>, referenced from method org.apache.http.impl.client.HttpClientBuilder.build
 VFY: unable to resolve direct method 13258: Lorg/apache/http/protocol/RequestUserAgent;.<init> (Ljava/lang/String;)V
 VFY: replacing opcode 0x70 at 0x017f
DexOpt: couldn't find static field Lorg/apache/http/impl/NoConnectionReuseStrategy;.INSTANCE
 VFY: unable to resolve static field 3085 (INSTANCE) in Lorg/apache/http/impl/NoConnectionReuseStrategy;
 VFY: replacing opcode 0x62 at 0x01f9
 DexOpt: unable to opt direct call 0x2413 at 0x231 in Lorg/apache/http/impl/client/HttpClientBuilder;.build
DexOpt: unable to opt direct call 0x33ca at 0x253 in Lorg/apache/http/impl/client/HttpClientBuilder;.build

 Could not find class 'javax.naming.ldap.LdapName', referenced from method org.apache.http.conn.ssl.DefaultHostnameVerifier.extractCN
: VFY: unable to resolve new-instance 1274 (Ljavax/naming/ldap/LdapName;) in Lorg/apache/http/conn/ssl/DefaultHostnameVerifier;
 VFY: replacing opcode 0x22 at 0x0004
 VFY: unable to resolve exception class 1270 (Ljavax/naming/InvalidNameException;)
 VFY: unable to resolve exception class 1270 (Ljavax/naming/InvalidNameException;)
 VFY: unable to find exception handler at addr 0x36
 VFY:  rejected Lorg/apache/http/conn/ssl/DefaultHostnameVerifier;.extractCN (Ljava/lang/String;)Ljava/lang/String;
 VFY:  rejecting opcode 0x0d at 0x0036
VFY:  rejected Lorg/apache/http/conn/ssl/DefaultHostnameVerifier;.extractCN (Ljava/lang/String;)Ljava/lang/String;
 Verifier rejected class Lorg/apache/http/conn/ssl/DefaultHostnameVerifier;
 threadid=10: thread exiting with uncaught exception (group=0xb4c87908)
 FATAL EXCEPTION: Thread-83
 java.lang.VerifyError: org/apache/http/conn/ssl/DefaultHostnameVerifier
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955)
at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)

at com.jp.service.HttpSpider.getHtml(HttpSpider.java:19)
at com.jp.service.GetHandpick.getArticle(GetHandpick.java:16)
at com.jp.fragment.HandpickF$1.run(HandpickF.java:40)





public class HttpSpider {


public static String getHtml(String url) throws Exception{
String html = null;
CloseableHttpClient httpClient=HttpClients.createDefault();   // 这里好像有问题。。。
try {
HttpGet httpGet=new HttpGet(url);
ResponseHandler<String> responseHandler=new ResponseHandler<String>() {

@Override
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
           
int code=response.getStatusLine().getStatusCode();
if(code>=200&&code<300){
HttpEntity entity=response.getEntity();
return entity!=null ? EntityUtils.toString(entity):null;
}else
throw new ClientProtocolException("Unexpected response status: " + code);
}

};
html=httpClient.execute(httpGet,responseHandler);
} catch (Exception e) {
   httpClient.close();
}
return html ;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值