1
私の学校のWebサービスからデータを取得したいと考えています。私はEclipseでコードを書いています:Android HttpsConnection - 内部サーバーエラー
List<Predmet> getInfo(String osobniCislo) throws IOException
{
String target = "https://stag-ws.zcu.cz/ws/services/rest/rozvrhy/getRozvrhByStudent?osCislo="
+ "A12B0141P"
+ "&outputFormatEncoding=windows-1250";
URL url = new URL(target);
HttpsURLConnection https = (HttpsURLConnection)url.openConnection();
https.setConnectTimeout(5000); // 5s timeout
https.setRequestMethod("GET");
https.setInstanceFollowRedirects(true);
https.setUseCaches(false);
https.setDoOutput(true);
https.connect();
//Response cod
int responseCode = https.getResponseCode();
System.out.println(https.getResponseMessage());
}
このコードはEclipseでうまく動作し、私は欲しいものを手に入れます。しかし、Androidスタジオにコピーしたとき、私は500 - Server Internal Error
になっています。私はマニフェストで特権を持っています:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
およびその他のウェブサイトは正常に動作します。誰かがどこに問題があるのか考えているのですか?
最初から間違いがあるのは、GETリクエストを試みているのに、あなたの要求をPOSTに設定している 'setDoOutput(true)'を呼び出すことです。 GETリクエストをしたいのであれば、 'setRequestMethod(" GET ")'や 'setDoOutput(true)'は必要ありません。 'HttpsURLConnection'クラスはデフォルトでGETリクエストを使うように設定されています。 – NoChinDeluxe