HttpWebRequest missing members


  • I am building a Silverlight 3 application using MSBuild. I am attempting to POST data in a HttpWebRequest, and I get error CS1061:
    'System.Net.HttpWebRequest' does not contain a definition for 'ContentLength'. Here is a code snippet:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
    request.Method = "POST";
    // Create POST data and convert it to a byte array.
    string postData = "&items=7";
    postData += "&data="+String.Format("{0}", recnbr);
    postData += "&delay=false";
    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    request.ContentLength = byteArray.Length;   [ERROR HERE]
    request.ContentType = "application/x-www-form-urlencoded";

    I also get the same error for 'GetRequestStream'.

    On the internet I find sample code like this that seems to work.  What am I missing?


    Monday, December 21, 2009 12:23 PM


  • Siberz wrote:
    'System.Net.HttpWebRequest' does not contain a definition for 'ContentLength'.

    Correct. This property is not available in the Silverlight .NET Framework. I believe the system sets this for you based on how much data is written to the request stream. See the "Remarks" section here:
    HttpWebRequest.Headers Property[^]


    Siberz wrote:
    I also get the same error for 'GetRequestStream'.

    You'll need to use BeginGetRequestStream() and EndGetRequestStream() in Silverlight.



    Siberz wrote:
    Searching the Internet, I found no answers.

    Silverlight Documentation[^]
    HttpWebRequest Members[^]

    Monday, December 21, 2009 7:34 PM