Problem with sending an image file with post request RRS feed

  • Question

  • User1564952282 posted

    Hello, i am writing a smallapplication for my PDA to send an image to my webserver. This is the code I use (I removed all non-essential code and only sent a small string:

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"http://testtracker.reperion.com:2020/WebForm1.aspx");

    string postData = @"postName=" + postName;

    byte[] data = encoding.GetBytes(postData);

    req.AllowWriteStreamBuffering = true; //required for bug workaround

    req.Method = "POST";

    req.Timeout = 28000;

    req.ContentType = "multipart/form-data";

    req.ContentLength = data.Length;

    Stream newStream = req.GetRequestStream();

    BinaryWriter oWriter = new BinaryWriter(newStream);


    WebResponse result = req.GetResponse();

    Stream receiveStream = result.GetResponseStream();

    StreamReader sr = new StreamReader(receiveStream, Encoding.UTF8);


    When I run my program I get an exception that says:


    however no more information was given!! How can I resolve this?





    Monday, December 18, 2006 11:12 AM


  • User1564952282 posted

    Ok, I found the solution to this problem myself.

    It appears that before you can issue the GetResponse the stream that was used to write the request (here oWriter) must be Closed. This is different behaviour than on the desktop environment.

    I found that out by making the real message of the exception available. This message was not available as a result of a not deployed diagnostics cab file:

    C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\Diagnostics and choose the file for your language.


    Thanks for all the answers [:D]



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 21, 2006 3:18 AM