0

応答から完全なコンテンツを読み取る際に問題に直面しています。デコーダーの長さが応答コンテンツの長さに従って来ていません。ラインで問題が発生しています。

int read = responseStream.EndRead(asyncResult); 

// read の値は、応答に従って非常に小さくなります。

int len = rs.StreamDecode.GetChars(rs.BufferRead, 0, read, charBuffer, 0);

以下は同じための私のコードです

private void ReadQtoRCallBack(IAsyncResult asyncResult)
{
   // Get the RequestState object from AsyncResult.
   RequestState rs = (RequestState)asyncResult.AsyncState;

   // Retrieve the ResponseStream that was set in RespCallback. 
   Stream responseStream = rs.ResponseStream;

   // Read rs.BufferRead to verify that it contains data. 
   int read = responseStream.EndRead(asyncResult);
   if (read > 0)
   {
      // Prepare a Char array buffer for converting to Unicode.
      Char[] charBuffer = new Char[BUFFER_SIZE];

      // Convert byte stream to Char array and then to String.
      // len contains the number of characters converted to Unicode.
      int len = rs.StreamDecode.GetChars(rs.BufferRead, 0, read, charBuffer, 0);

      String str = new String(charBuffer, 0, len);

      // Append the recently read data to the RequestData stringbuilder
      // object contained in RequestState.
      RequestData.Append(PureAnalyzer_WebApp.DoubleAt + rs.ResultName + PureAnalyzer_WebApp.DoubleColon);

      // ESResultBE ESObj = new ESResultBE();
      System.Web.Script.Serialization.JavaScriptSerializer JsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
      ESResultBE ObjESResultBE;
      string Result = "";         

      RequestData.Append(Encoding.ASCII.GetString(rs.BufferRead, 0, read).ToString());

      // Continue reading data until 
      // responseStream.EndRead returns –1.
      IAsyncResult ar = responseStream.BeginRead(
                           rs.BufferRead, 0, BUFFER_SIZE,
                           new AsyncCallback(ReadQtoRCallBack), rs);
   }
   else
   {
      // Close down the response stream.
      responseStream.Close();
      if (ResponseFlag[rs.ResultName] != "1")
      {
        ResponseFlag[rs.ResultName] = "1";
        CompleteCount++;
      }
      // Set the ManualResetEvent so the main thread can exit.
      allDone.Set();
   }
   return;
}
4

0 に答える 0