Condividi tramite


WebRequest.Create Method (String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Initializes a new WebRequest instance for the specified URI scheme.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

Syntax

'Declaration
Public Shared Function Create ( _
    requestUriString As String _
) As WebRequest
public static WebRequest Create(
    string requestUriString
)

Parameters

  • requestUriString
    Type: System.String
    The URI string that identifies the Internet resource.

Return Value

Type: System.Net.WebRequest
A WebRequest descendant for the specific URI scheme.

Exceptions

Exception Condition
NotSupportedException

The request scheme specified in requestUriString has not been registered.

ArgumentNullException

requestUriString is nulla null reference (Nothing in Visual Basic).

SecurityException

The caller does not have permission to connect to the requested URI or a URI that the request is redirected to.

UriFormatException

The URI specified in requestUriString is not a valid URI.

Remarks

The Create(String) method returns a descendant of the WebRequest class determined at run time as the closest registered match for requestUri.

For example, when a URI beginning with http:// is passed in requestUri, an HttpWebRequest is returned by Create.

The .NET Framework includes support for the http:// and https:// URI schemes. Custom WebRequest descendants to handle other requests are registered with the RegisterPrefix method.

The Create(String) method uses the requestUriString parameter to create a Uri instance that it passes to the new WebRequest.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 If you attempt to access a file from an FTP site, the application throws NullRefrenceException instead of NotSupportedException.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

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