3

次の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を想定しています。

私は何かが足りないのですか?

4

1 に答える 1

0

まず、すべてのリクエスト タイプ (PUT、DELETE、POST、GET) を使用する HTTP(s) リクエスト用に特別に開発された Google API である Volley を使用することを強くお勧めします。これを見ることをお勧めします: Google I/O のビデオ そして、このチュートリアルに従ってください (問題をカバーしています):チュートリアル リンク

試してみたい場合はお知らせください。喜んでお手伝いさせていただきます。

じゃあ !

于 2013-10-31T05:48:40.913 に答える