HttpURLConnection是否适用于sdk22?

时间:2016-05-11 06:02:10

标签: android

适用于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());

1 个答案:

答案 0 :(得分:0)

是的它没有任何问题,并且差异不会导致任何问题

HttpUrlConnection来自 API Level 1 ,您可以从docs进一步了解更多信息。

HttpUrlConnection用于弃用的Apache HttpClient

是一种很好的做法