質問

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

    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();
    }
    }
役に立ちましたか?

解決

だからこのフォローアップするために、ここで私はそれを解決する方法です。

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...
}

このようにそれらを呼び出すことはメッセージとエラー・ストリームを生成しているようです。提案をありがとう!

他のヒント

"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

は、サーバーの制御にはありますか?言い換えれば、あなたは、ポートへのサーバ上で動作し、リッスンがアクセスしようとしているというプロセスを記述したのですか?

あなたがいた場合、あなたはまた、それをデバッグ、なぜあなたの処理に戻る404を見ることができる必要があります。

あなたがしなかった場合、(などのHTTPサーバー、それはあなたのHTTP(S)要求に応答する呼び出しコンポーネント、)あなたのアーキテクチャを説明し、我々はそこからそれを取るでしょう。

非常に最も簡単なケースでは、HTTPサーバは、いくつかのPHPスクリプトに制御をもたらすApacheサーバであることの、それはApacheが何にあなたの要求を割り当てることができなかったことを意味します。ほとんどの場合、Webサーバーの設定ミス。いくつかのより多くの詳細を提供し、私たちはあなたをお手伝いします。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top