アプリケーションで HttpURLConnection を使用しようとしています。リクエスト メソッドを 'GET' に設定しましたが、出力ストリームを取得しようとすると、メソッドが 'POST' に変更されました。それが理由かどうかはわかりませんが、「POST」を使用してリクエストを送信すると、JSON サーバー (JAX-RS を使用) が空白のページを返します。
ここに私のコードのスニペットがあります:
// Create the connection
HttpURLConnection con = (HttpURLConnection) new URL(getUrl() + uriP).openConnection();
// Add cookies if necessary
if (cookies != null) {
for (String cookie : cookies) {
con.addRequestProperty("Cookie", cookie);
Log.d("JSONServer", "Added cookie: " + cookie);
}
}
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.setRequestMethod("GET");
con.setConnectTimeout(20000);
// Add 'Accept' property in header otherwise JAX-RS/CXF will answer a XML stream
con.addRequestProperty("Accept", "application/json");
// Get the output stream
OutputStream os = con.getOutputStream();
// !!!!! HERE THE REQUEST METHOD HAS BEEN CHANGED !!!!!!
OutputStreamWriter wr = new OutputStreamWriter(os);
wr.write(requestP);
// Send the request
wr.flush();
ご回答ありがとうございます。エリック