views:

1176

answers:

3

I am trying to use an HttpWebRequest object in Silverlight 2.0, to do a "POST".

Upon return from the BeginGetStream method I end up with the following error :

Message: "Specified method is not supported." StackTrace: " at System.Net.BHWRAsyncResult.get_AsyncWaitHandle()"

Here's some sample code: Note I have used fiddler to see if anything is being sent across the wire and there is no network activity.

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri("http://someurl"));
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.Accept = "text/plain, */*";
        req.Headers["X-Requested-With"] = "XMLHttpRequest";

        AsyncCallback callBack = new AsyncCallback(streamResponse);

        req.BeginGetRequestStream(callBack, null);

Thanks, Dave

A: 

I just ran into this a while ago. Off the top of my head:

1) clientaccesspolicy.xml / crossdomain.xml isn't around on the server you are calling. Like flash, silverlight won't talk to a domain that doesn't have one.

1.1) Does fiddler log 404 errors? If it doesn't, you won't see the failed attempts Silverlight is making trying to get those policy files.

2) Failing that, sending your custom header might be upsetting things.

Cory R. King
Thanks for the reply. Fiddler will show 404's so I'm quite sure that is not the problem. I've also tried taking out the custom header but still no joy.
A: 

Hello Dave, I just found one solution for this problem. HTTP Client need to know Content-Length to fill the Content-Length HTTP header value. Client can'not start request before it length became known. When You get RequestStream WebRequest can'not know how much bytes you will send to server. You must Close stream to commit Content-Length and only after closing the RequestStream You can call BeginGetResponse. It is strange that this not done inside WebRequest. Hope this helps, Dmitry

A: 

http://support.microsoft.com/kb/225342

I'm trying to figure this out as well

internet man