-1
我試圖找到下面的代碼的等價物,因爲有些類不推薦使用。Android - 相當於Apache棄用類
try
{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
catch (Exception e)
{
e.printStackTrace();
}
到目前爲止,我已經寫了這一點,但它不工作
HttpURLConnection httpUrlConnection = null;
try
{
URL mUrl = new URL(url);
httpUrlConnection = (HttpURLConnection) mUrl.openConnection();
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.connect();
is = new BufferedInputStream(httpUrlConnection.getInputStream());
httpUrlConnection.disconnect();
}
catch(Exception e)
{
e.printStackTrace();
}
請求後我發現了一個例外,所以我覺得有什麼不對我的請求。
'httpUrlConnection.disconnect();'你怎麼想,你以後會發生到你的InputStream斷開? – njzk2