次のJavaを実行しています。これは、Androidデバイスから送信されるJSONデータを含むHttpURLConnectionPUTリクエストです。これが機能した後、発生した例外を処理します。GETは正常に機能しています。
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(nameString, pwdString.toCharArray());
}
});
url = new URL(myURLString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
urlConnection.setRequestMethod("PUT");
urlConnection.setRequestProperty("Content-Type", "application/json");
OutputStream output = null;
try {
output = urlConnection.getOutputStream();
output.write(jsonArray.toString().getBytes());
} finally {
if (output != null) { output.close(); }
}
int status = ((HttpURLConnection) urlConnection).getResponseCode();
System.out.println("" + status);
urlConnection.disconnect();
予期しないプロパティがリクエストをブロックしているというHTTP500エラー(内部エラーコード)を受け取りました。JSONArrayは、私が知っているキーが正しいJSONObjectで構成されています。サーバーはかなり標準的であり、JSON本体を持つHTTPPUTを想定しています。
私は何かが足りないのですか?