Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

WebRequestCreator Class

Silverlight

Provides objects for specifying whether the browser or the client handles HTTP requests and responses.

System.Object
  System.Net.Browser.WebRequestCreator

Namespace:  System.Net.Browser
Assembly:  System.Windows (in System.Windows.dll)
public static class WebRequestCreator

The WebRequestCreator type exposes the following members.

  NameDescription
Public propertyStatic memberBrowserHttpGets an object that specifies browser HTTP handling for Web requests and responses.
Public propertyStatic memberSupported by Silverlight for Windows PhoneClientHttpGets an object that specifies client HTTP handling for Web requests and responses.
Top

With Silverlight, you can specify whether the browser or the client provides HTTP handling for your Silverlight-based applications. By default, HTTP handling is performed by the browser and you must opt-in to client HTTP handling. You typically pass the properties of this class to the RegisterPrefix method of WebRequest to specify the HTTP handling for HTTP requests and responses.

The following is a list of scenarios that you would typically specify client HTTP handling for:

  • Using HTTP methods other than GET and POST.

  • Using response status codes, bodies and headers.

  • Sending HTTP XML requests such as messages to SOAP and REST services.

  • Manually managing cookies.

For more information on the differences between client and browser HTTP handling, see HTTP Communication and Security with Silverlight.

In addition to specifying whether to use browser or client HTTP handling, you can specify the scope for the handling. For example, you can specify HTTP handling for all messages, for a particular domain, or for a single request object. For more information, see How to: Specify Browser or Client HTTP Handling.

After you specify client or browser HTTP handling for a particular scheme or domain, you cannot change how HTTP messages to the domain or scheme are handled. If you try to call RegisterPrefix a second time for the same domain or prefix, the method will return false to indicate the register operation was not successful.

The following example shows you how to specify client HTTP handling for all messages.


bool httpResult = WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
bool httpsResult = WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);


...


if (httpResult == true)
{
    WebClient wc = new WebClient();
    wc.OpenReadAsync(new Uri("http://api.search.live.net/qson.aspx?query=Silverlight"));
    wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.