无法在Android Studio中解析符号HttpGet,HttpClient,DefaultHttpClient
问题描述:
我是我的应用程序中的android新手,正在与服务集成,因此当我导入所有这些jar文件时.它给出了一个错误:
Hi I am new for android in my app I am integrating with services so when I import all these jar files. It gives an error :
无法解析符号HttpGet,HttpClient,DefaultHttpClient.
Cannot resolve symbol HttpGet,HttpClient,DefaultHttpClient.
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
我的构建gradle:-
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
}
答
HttpClient在API级别22中已弃用,并在API级别23中已已删除.您必须使用URLConnection
.
HttpClient was deprecated in API Level 22 and removed in API Level 23. You have to use URLConnection
.
如果您仍然需要23,请将其添加到gradle ::
If you anyway need in 23, add this to your gradle::
android {
useLibrary 'org.apache.http.legacy'
}
注意:相反,我建议使用 OkHttp .
NOTE: Instead, I would recommend using OkHttp.