Sau khi thêm các thay đổi sau vào build.gradle ngay sau khi cập nhật lên cấp API Android mới nhất 23 (Marshmallow), tất cả các lớp org.apache.http không hoạt động.gói org.apache.http bị xóa ở cấp API 23. Phương án thay thế là gì?
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.myapp.package"
minSdkVersion 15
targetSdkVersion 23
versionCode 2
versionName "1.1"
}
}
Tôi đã kiểm tra "Báo cáo khác biệt về API Android" here. Nó nói rằng tất cả các lớp của org.apache.http đã bị loại bỏ. Ai đó có thể đề xuất thay thế là gì?
Đây là mã của tôi:
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();
}
HttpClient đã không được chấp nhận trong Android L, vì vậy tôi khuyên bạn nên sử dụng HttpURLConnection – user3641702