Bytes to be written to the stream exceed the Content-Length bytes size specified.
-
Hi.. I'm trying to upload a image file to the server using HttpWebRequest/HttpWebResponse. so i form a Postdata as and storing in a StringBuilder object (sbFormData)..
Content-Type: multipart/form-data; boundary=AaB03x --AaB03x Content-Disposition: form-data; name="submit-name" Larry --AaB03x Content-Disposition: form-data; name="files" Content-Type: multipart/mixed; boundary=BbC04y --BbC04y Content-Disposition: file; filename="file1.txt" Content-Type: text/plain ... contents of file1.txt ... --BbC04y Content-Disposition: file; filename="file2.gif" Content-Type: image/gif Content-Transfer-Encoding: binary ...contents of file2.gif... --BbC04y-- --AaB03x--
while adding the image content i read byte by byte and then adding to the sbFormData. But when i see the sbFormdata's length its not showing exact length. That is not adding the image content's length. Then setting the HttpWebRequest.Length to sbFormdata.Length..
httpWebRequest.ContentLength = sbFormData.Length;
after when i try to write the sbFormData to the httpWebRequest.GetRequestStream(), i get Error: "Bytes to be written to the stream exceed the Content-Length bytes size specified."try { StreamWriter s = new StreamWriter(httpWebRequest.GetRequestStream()); s.Write(sbFormData.ToString()); s.Close(); } catch (Exception e) { Debug.Print("Error in sending data " + e.Message); }
Please help me.. regards, nas
-
Hi.. I'm trying to upload a image file to the server using HttpWebRequest/HttpWebResponse. so i form a Postdata as and storing in a StringBuilder object (sbFormData)..
Content-Type: multipart/form-data; boundary=AaB03x --AaB03x Content-Disposition: form-data; name="submit-name" Larry --AaB03x Content-Disposition: form-data; name="files" Content-Type: multipart/mixed; boundary=BbC04y --BbC04y Content-Disposition: file; filename="file1.txt" Content-Type: text/plain ... contents of file1.txt ... --BbC04y Content-Disposition: file; filename="file2.gif" Content-Type: image/gif Content-Transfer-Encoding: binary ...contents of file2.gif... --BbC04y-- --AaB03x--
while adding the image content i read byte by byte and then adding to the sbFormData. But when i see the sbFormdata's length its not showing exact length. That is not adding the image content's length. Then setting the HttpWebRequest.Length to sbFormdata.Length..
httpWebRequest.ContentLength = sbFormData.Length;
after when i try to write the sbFormData to the httpWebRequest.GetRequestStream(), i get Error: "Bytes to be written to the stream exceed the Content-Length bytes size specified."try { StreamWriter s = new StreamWriter(httpWebRequest.GetRequestStream()); s.Write(sbFormData.ToString()); s.Close(); } catch (Exception e) { Debug.Print("Error in sending data " + e.Message); }
Please help me.. regards, nas
You are setting the content length to the number of characters in the string, but that is not the same as the number of bytes that the string uses when encoded. You have to encode the string first to get the size of the encoded data.
--- single minded; short sighted; long gone;
-
You are setting the content length to the number of characters in the string, but that is not the same as the number of bytes that the string uses when encoded. You have to encode the string first to get the size of the encoded data.
--- single minded; short sighted; long gone;