开发者

Can you set http headers when using HttpRequest object in Silverlight?

开发者 https://www.devze.com 2022-12-20 19:25 出处:网络
I\'m having trouble setting any HTTP header values when making a HttpRequest from Silverlight 3.0? Are HTTP Headers supported in Silverlight 3.0?

I'm having trouble setting any HTTP header values when making a HttpRequest from Silverlight 3.0?

Are HTTP Headers supported in Silverlight 3.0?

The following code throw开发者_运维技巧s an exception when the request callback is called:

        var url = new Uri("http://lonmw32795/RBSM_Portal_RESTfulWebService/HostInterrogationService.svc/host/environment");
        req = (HttpWebRequest)WebRequest.Create(url);
        req.Headers[HttpRequestHeader.Pragma] = "no-cache";
        req.Method = "GET";

        req.BeginGetResponse(new AsyncCallback(WebComplete), req);    

The exception type is System.NotSupportedException - WTF!

Anyone got any ideas?

Cheers

AWC


Note the documentation for the WebHeaderCollection, most of the useful headers are restricted, it doesn't list pragma but then it also says that restricted headers is not limited to the list provided.

These restrictions are in place since the underlying browser would normally handle http requests and it would therefore control such headers using its own algorithms.

It may be possible to do this with the ClientHttp like this:-

    var url = new Uri("http://lonmw32795/RBSM_Portal_RESTfulWebService/HostInterrogationService.svc/host/environment");
    req = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(url);

Note that you will need to manage any cookies needed manually which may be a little tricky if the cookies are set as part of a response to requests that use BrowserHttp.


The simple answer is no it doesn't - if you want to create a HttpRequest you have to use the WebRequestCreator class.

check out this blog post for more info.

0

精彩评论

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