2

ここで msdn の例を使用しています: http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx

FileStream を MemoryStream に変更しましたが、バイトが読み取られません

FileStream に戻すと正常に動作します。

どんな手掛かり?

ありがとう

        CompressMemoryStream();
        Stream requestStream = _request.EndGetRequestStream(ar);
        const int bufferLength = 2048;
        byte[] buffer = new byte[bufferLength];
        int count = 0;
        int readBytes = 0;

        do
        {
            //MemoryStream _compressedOutStream 
            //is created/filled by 'CompressMemoryStream()'
            readBytes = _compressedOutStream.Read(buffer, 0, bufferLength);
            requestStream.Write(buffer, 0, readBytes);
            count += readBytes;
        }
        while (readBytes != 0);
        requestStream.Close();
        state.Request.BeginGetResponse(
            new AsyncCallback(EndGetResponseCallback),
            state
        );
4

1 に答える 1

3

readBytesループの最初の繰り返しの値は?

私の最初の推測では、あなたは私がよく犯すのと同じ過ちを犯したのではないでしょうか。その場合、readBytesストリームの最後にいるため、最初の (そして唯一の) ループ反復でゼロになります。読み取るものはありません。

stream.Position = 0読み始める前に設定してみてください。

于 2010-09-24T19:45:14.060 に答える