import org.apache.http.clIEnt.methods.CloseablehttpResponse; import org.apache.http.clIEnt.methods.httpGetHC4;import org.apache.http.impl.clIEnt.CloseablehttpClIEnt;import org.apache.http.impl.clIEnt.httpClIEntBuilder;public class httpHelper{ private String base; public httpHelper (String base) { this.base = base; } public String doGet (String path) { try { CloseablehttpClIEnt clIEnt = httpClIEntBuilder.create().build(); httpGetHC4 get = new httpGetHC4(path); CloseablehttpResponse response = clIEnt.execute(get); return ""; } catch (Exception e) { return null; } }}
问题是AndroID Studio标记了这一行
clIEnt.execute(get);
有错误:
说“无法访问org.apache.http.clIEnt.httpClIEnt”
这是我的gradle文件:
apply plugin: 'com.androID.application'androID { compileSdkVersion 23 buildToolsversion "23.0.0" defaultConfig { applicationID "principal.halloween" minSdkVersion 16 targetSdkVersion 23 versionCode 1 versionname "1.0" } buildTypes { release { MinifyEnabled false proguardfiles getDefaultProguardfile('proguard-androID.txt'),'proguard-rules.pro' } }}dependencIEs { compile filetree(dir: 'libs',include: ['*.jar']) compile 'com.androID.support:appcompat-v7:23.0.0' compile 'com.pubnub:pubnub-androID:3.7.5' compile 'com.Google.code.gson:gson:2.3.1' compile group: 'org.apache.httpcomponents',name: 'httpclIEnt-androID',version: '4.3.5.1' compile 'org.apache.httpcomponents:httpclIEnt:4.3.6'}解决方法 在AndroID SDK 23中
不推荐使用httpClIEnt,因为它推断,您可以在httpURLConnection中迁移代码
https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client
您可以使用此功能,但不建议使用此功能
androID { uselibrary 'org.apache.http.legacy'}
对于httpURLConnection
URL url = new URL(urlString);httpURLConnection connection = (httpURLConnection)url.openConnection();connection.setRequestMethod("GET");connection.setDoinput(true);connection.connect();总结
以上是内存溢出为你收集整理的Android无法访问org.apache.http.client.HttpClient全部内容,希望文章能够帮你解决Android无法访问org.apache.http.client.HttpClient所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)