Androidアプリを実装しましたが、これまでのところ問題はありませんでした。Android API 21非同期GETリクエストが機能しない
しかし、非同期のGETリクエストを取得すると約3日かかりましたが、まだ進捗状況はありません。
私はAndroidのドキュメンテーションを使用してみましたし、いくつかのコード..なし結果 を書きました。そして私は再び何の結果..オンラインありませんほぼすべてのソリューションを試してみました
あなたは私の非同期GET要求に対するソリューションを提供して頂けますかAndroid APIレベル21では?
getRequest task = new getRequest();
String contents = null;
try {
contents = task.execute(url).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
、ここで私のクラスは
だpublic static class getRequest extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String result = "";
URL url;
HttpURLConnection urlConnection;
try {
url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("headerFieldName", "I took out the fields here since they were personal");
InputStream in = urlConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(in);
int data = reader.read();
while (data != -1) {
result += (char) data;
data = reader.read();
}
return result;
} catch(Exception e) {
e.printStackTrace();
return "Failed";
}
}
}
私もorg.apache使用してみましたが、図書館は23
ありがとうAPIレベルから削除されました!ここで
一部のコードを投稿してください。あなたが今まで持っているものを見て、私たちがあなたを助けてくれるようになるでしょう。 –
@TodorKostovコードを追加しました。ありがとう! – Illinois47