5

私は解決できないように見える HttpsURLConnection に問題があります。基本的に、私はいくつかの情報をサーバーに送信しています。そのデータの一部が間違っている場合、サーバーは 500 応答コードを送信します。ただし、応答で、データのどのビットが間違っていたかを知らせるメッセージも送信します。問題は、メッセージを読み込んだときにメッセージが常に空であることです。これは、ストリームを読み取る前に常に filenotfound 例外がスローされるためだと思います。私は正しいですか?エラーストリームも読み込もうとしましたが、これは常に空です。ここにスニペットがあります:

    conn = (HttpsURLConnection) connectURL.openConnection();
    conn.setDoOutput(true);
    conn.setConnectTimeout(30000);
    conn.setReadTimeout(30000);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Length",
         Integer.toString(outString.getBytes().length));
    DataOutputStream wr = new DataOutputStream(conn
      .getOutputStream());
    wr.write(outString.getBytes());
    wr.flush();
    wr.close();
    if(conn.getResponseCode>400{

    String response = getErrorResponse(conn);

    public String getErrorResponse(HttpsURLConnection conn) {
    Log.i(TAG, "in getResponse");
    InputStream is = null;
    try {

     //is = conn.getInputStream();
    is = conn.getErrorStream();
    // scoop up the reply from the server
    int ch;
    StringBuffer sb = new StringBuffer();
    while ((ch = is.read()) != -1) {
     sb.append((char) ch);
    }
    //System.out.println(sb.toString());
    return sb.toString();
    // return conferenceId;
   }
    catch (Exception e){
    e.printStackTrace();
    }
    }
4

3 に答える 3

3

これをフォローアップするために、これが私がそれを解決した方法です:

public static String getResponse(HttpsURLConnection conn) {
    Log.i(TAG, "in getResponse");
    InputStream is = null;
    try {
        if(conn.getResponseCode()>=400){
            is = conn.getErrorStream();
        }
        else{
            is=conn.getInputStream();
        }
        ...read stream...
}

このように呼び出すと、メッセージ付きのエラー ストリームが生成されたようです。提案をありがとう!

于 2010-10-29T11:28:46.700 に答える
0

サーバーを管理していますか?つまり、サーバー上で実行され、アクセスしようとしているポートをリッスンするプロセスを作成しましたか?

そうした場合は、それをデバッグして、プロセスが404を返す理由を確認することもできるはずです。

そうでない場合は、アーキテクチャ(HTTPサーバー、HTTP(S)要求に応答するために呼び出すコンポーネントなど)を説明してください。そこから取得します。

非常に単純なケースでは、HTTPサーバーがApacheサーバーであり、PHPスクリプトを制御している場合、Apacheはリクエストを何にも割り当てることができなかったことを意味します。Webサーバーの設定ミスの可能性があります。詳細をお知らせください。サポートさせていただきます。

于 2010-09-30T23:08:09.453 に答える
0

content-type リクエスト プロパティを次のように設定してみてください"application/x-www-form-urlencoded"

このリンクにも同じことが記載されています: http://developers.sun.com/mobility/midp/ttips/HTTPPost/

The Content-Length and Content-Type headers are critical because they tell the web server how many bytes of data to expect, and what kind, identified by a MIME type.

In MIDP clients the two most popular MIME types are application/octet-stream, to send raw binary data, and application/x-www-form-urlencoded, to send name-value pairs

于 2010-09-28T04:23:19.587 に答える