在更新到最新的android API级别23(Marshmallow)之后,通过build.gradle添加以下更改后,所有org.apache.http类都无效.
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.myapp.package"
minSdkVersion 15
targetSdkVersion 23
versionCode 2
versionName "1.1"
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里查看了"Android API差异报告" .它说所有的org.apache.http类都被删除了.有人可以建议什么是替代方案吗?
这是我的代码:
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(address);
httpPost.setEntity(new StringEntity("{\"longUrl\":\""+longUrl+"\"}"));
httpPost.setHeader("Content-Type", "application/json");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)