私はアンドロイドアプリを書いていますが、これは以前はうまくいきましたが、最近、動作していませんでした。下記のリンクからJSONコードの解析マイアプリ: http://opendata.epa.gov.tw/ws/Data/RainTenMin/?%24format=jsonアンドロイドHttpURLConnectionを取得し続ける302
は、私は私のアプリが動作しない理由は、応答コードが302である、だから私は、インターネット上でグーグルとのgetHeaderField(「場所」)を使用することであることがわかりました私のコード で、私はリダイレクトされたURLは、だから私はhttpsでリンクに私のパースのURLを変更し、しかし、この時間は、 HttpURLConnectionのはIOEexceptionが、私はそれを修正することができますどのように、あなたのためにあなたに感謝スロー https://opendata.epa.gov.tw/ws/Data/RainTenMin/?%24format=json
であることがわかりました助けて。
private static String httpRequest(URL rurl) throws IOException{
String response = "";
if (rurl == null) {
return response;
}
HttpURLConnection connection = null;
InputStream inputStream = null;
try {
connection = (HttpURLConnection) rurl.openConnection();
connection.setConnectTimeout(20000);
connection.setRequestMethod("GET");
connection.setReadTimeout(25000);
connection.connect();
//200 means correctly connected
int responseCode = connection.getResponseCode();
if (responseCode ==200) {
inputStream = connection.getInputStream();
response = readStream(inputStream);
}
else {
MainActivity.connect=false;
Log.i(logtag, "Error!! Response code is " + responseCode);
}
}
catch (IOException e) {
MainActivity.connect=false;
Log.e(logtag, "bad internet!!");}
finally {
if (inputStream != null) {
inputStream.close();
}
if (connection != null) {
connection.disconnect();
}
}
return response;
}
は、以下のエラーのlogcatです:
E/query: bad internet!!
、その後、(名前はhttpsConnectionを使用https://developer.android .com/reference/javax/net/ssl/HttpsURLConnection.html) – Ozan
エラーのログcatを追加してください – aliaksei
話題にならないようにしたいのですが、なぜあなたは[retrofit]しようとしませんか( http://square.github.io/retrofit/)? – crgarridos