开发者

ProtocolViolation Exception on request stream.write() in windows mobile 6.5

开发者 https://www.devze.com 2023-03-08 08:52 出处:网络
In my windows mobile application i am trying to write a video file with boundaries. If i place the boundaries i am receiving protocol exception but if i am not using any boundary it works fine.

In my windows mobile application i am trying to write a video file with boundaries. If i place the boundaries i am receiving protocol exception but if i am not using any boundary it works fine.

Below is my code

Stream requestStream = request.GetRequestStream();
        byte[] boundaryData = System.Text.Encoding.ASCII.GetBytes(twoHyphens+boundary+lineEnd);
        byte[] boundaryData1 = System.Text.Encoding.ASCII.GetBytes(twoHyphens + boundary + twoHyphens + lineEnd );

开发者_运维技巧        String headertemp = "Content-Disposition: form-data; name=\"uploadedfile\";filename=\""+ GetCamera.videoFilePath+ "\""+ lineEnd;
        byte[] headerData = System.Text.Encoding.ASCII.GetBytes(headertemp);
        byte[] lineend = System.Text.Encoding.ASCII.GetBytes(lineEnd);

        requestStream.Write(boundaryData, 0, boundaryData.Length);
        requestStream.Write(headerData, 0, headerData.Length);
        requestStream.Write(lineend, 0, lineend.Length);
        using (Stream video = File.OpenRead(GetCamera.videoFilePath))
        {
            byte[] buffer = new byte[1024];

            while ((bytesRead = video.Read(buffer, 0, buffer.Length)) > 0)
            {
                requestStream.Write(buffer, 0, bytesRead);
            }
        }
        requestStream.Write(lineend, 0, lineend.Length);
        requestStream.Write(boundaryData1, 0, boundaryData.Length);
        requestStream.Close();
        requestStream.Dispose();

Please help me to solve this issue.

Please forward your valuable suggestions.


I donot know the reason but when i increased the value for content length property,it worked fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消