1

Nokia N97電話からサーバーにファイルをアップロードしました。すべて正常に動作しますが、ファイルをアップロードした後、サーバーから応答を取得したいと思います。問題は、30分以上経っても応答がないことです。httpConnection.getResponseCode()のコードブロックが応答を待っているのがわかります。Sony Ericssonでテストしたところ、応答が非常に速いので、NokiaN97の問題だと思います。(他の電話でも正常に動作するため、サーバーの問題ではありません)

なぜこのことがノキアでのみ起こるのか誰かが知っていますか?

コードスニペットは次のとおりです。

public uploadFile(){

       httpConn = (HttpsConnection) Connector.open(url, Connector.READ_WRITE);
        ...
       //set httpConn parameters and request method 
       ...

       writeParametersAndFileName(os, "text/plain");


       **writeFileToStream(os);** 

       os.write("\r\n".getBytes());
       os.write("--".getBytes());

       os.write(boundary.getBytes());

       os.write("--".getBytes());
       os.write("\r\n".getBytes());

        *//here code blocks on Nokia N97. Same thing happens if I use os.flush() after
        // I send chunks of the file*
         .....
        codeResp = httpConn.getResponseCode();
        // check condition
        checkResponseHeader();

}

public writeFileToStream() {

        InputStream is = null;
        FileConnection c = null;
        try
        {
           c = (FileConnection) Connector.open("file:///"+ sourcePath, Connector.READ);

           if(c.exists()) {
               is = c.openInputStream();

               long fs = c.fileSize();
               while (total < fs) {
                    byte[] data = new byte[512];
                    int readAmount = is.read(data,0,512);                       
                    total += readAmount;
                    os.write(data, 0, readAmount);


            }

            //os.flush();
        }
        catch (IOException ex) {
           //               
        }
        finally
        {
           //close connection

        }

}

4

1 に答える 1

4

あなたはあなたのファイルがアップロードされたと思うだけです。

getResponseCode()の呼び出しは、HttpConnectionを実際にサーバーに接続させる最初の呼び出しです。

ファイルをアップロードするまで戻りません。おそらく1分以上かかります。

これは、JSR-118のHttpConnection仕様によると完全に有効な動作です。

"次の方法では、接続がセットアップ状態のときに接続状態に移行します。

* openInputStream
* openDataInputStream
* getLength
* getType
* getEncoding
* getHeaderField
* getResponseCode
* getResponseMessage
* getHeaderFieldInt
* getHeaderFieldDate
* getExpiration
* getDate
* getLastModified
* getHeaderField
* getHeaderFieldKey 

「」

これを試した他の電話はN97よりも強力ではなく、OutputStreamをフラッシュする必要があるため、仕様に従ってサーバーに接続する前に接続する必要があります。

于 2009-12-09T11:13:25.817 に答える