9
Tôi nâng cấp lên phiên bản sdk mới nhất 23. Bây giờ, một số mã của tôi không hoạt động nữa. đây là một lớp học tôi đã có trước để nhận json:android - gói org.apache.http không tồn tại sdk 23
public class Spots_tab1_json {
static String response = null;
public final static int GET = 1;
public final static int POST = 2;
public Spots_tab1_json() {
}
public String makeServiceCall(String url, int method) {
return this.makeServiceCall(url, method, null);
}
public String makeServiceCall(String url, int method,
List<NameValuePair> params) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpEntity httpEntity = null;
HttpResponse httpResponse = null;
if (method == POST) {
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Cache-Control", "no-cache");
if (params != null) {
httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
}
httpResponse = httpClient.execute(httpPost);
} else if (method == GET) {
if (params != null) {
String paramString = URLEncodedUtils.format(params, "UTF-8");
url += "?" + paramString;
}
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Cache-Control", "no-cache");
httpResponse = httpClient.execute(httpGet);
}
httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
}
là có bất kỳ thay thế? nếu có, nó nên được thay thế bằng cái gì?
nhờ
nhờ trả lời nhưng tôi đã cố gắng để thêm mã này vào cả hai gradles nhưng nó không công việc . nó mang lại cho tôi phương pháp DSL Gradle không tìm thấy: 'useLibrary()' lỗi. – navidjons
http://stackoverflow.com/questions/30856785/how-to-add-apache-http-api-legacy-as-compile-time-dependency-to-build-grade kiểm tra tại đây , tôi đoán bạn cần phải cập nhật sự phụ thuộc –