适用于Android API 23的HttpURLConnection是否适用于Android API22? 我试图为超过4.0的Android版本编程。 我不确定sdk22和sdk23之间的区别是否会导致问题
// http client
URL url = new URL(url1);
HttpURLConnection httpClient = (HttpURLConnection) url.openConnection();
httpClient.setRequestMethod("POST");
httpClient.setUseCaches(false);
httpClient.setDoInput(true);
httpClient.setDoOutput(true);
httpClient.setRequestProperty("Connection", "Keep-Alive");
httpClient.addRequestProperty("Content-length", reqEntity.getContentLength() + "");
OutputStream os = httpClient.getOutputStream();
reqEntity.writeTo(httpClient.getOutputStream());
os.close();
httpClient.connect();
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
return readStream(httpClient.getInputStream());
答案 0 :(得分:0)
是的它没有任何问题,并且差异不会导致任何问题
HttpUrlConnection
来自 API Level 1 ,您可以从docs进一步了解更多信息。
将HttpUrlConnection
用于弃用的Apache HttpClient
类