Language

WebRequest.Create メソッド

定義

新しい WebRequestを初期化します。

オーバーロード

名前 説明
Create(String)
古い.

指定した URI スキームの新しい WebRequest インスタンスを初期化します。

Create(Uri)
古い.

指定した URI スキームの新しい WebRequest インスタンスを初期化します。

Create(String)

ソース:
WebRequest.cs
ソース:
WebRequest.cs
ソース:
WebRequest.cs
ソース:
WebRequest.cs
ソース:
WebRequest.cs

注意事項

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.

指定した URI スキームの新しい WebRequest インスタンスを初期化します。

public:
 static System::Net::WebRequest ^ Create(System::String ^ requestUriString);
public static System.Net.WebRequest Create(string requestUriString);
[System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Net.WebRequest Create(string requestUriString);
static member Create : string -> System.Net.WebRequest
[<System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member Create : string -> System.Net.WebRequest
Public Shared Function Create (requestUriString As String) As WebRequest

パラメーター

requestUriString
String

インターネット リソースを識別する URI。

返品

特定の URI スキームの WebRequest 子孫。

属性

例外

requestUriStringで指定された要求スキームが登録されていません。

requestUriString は nullです。

呼び出し元には、要求された URI または要求のリダイレクト先の URI に接続するための WebPermissionAttribute アクセス許可がありません。

requestUriStringで指定された URI が有効な URI ではありません。

注: < Windows Store アプリの>.NET または Portable クラス ライブラリでは、代わりに基底クラスの例外 をキャッチします。

例

次の例では、 Create を使用して HttpWebRequest インスタンスをインスタンス化します。 ターゲット URL を表す文字列がコンストラクター パラメーターとして使用されます。

Uri ourUri = new Uri(url);            

// Create a 'WebRequest' object with the specified url. 
WebRequest myWebRequest = WebRequest.Create(url); 

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Use "ResponseUri" property to get the actual Uri from where the response was attained.
if (ourUri.Equals(myWebResponse.ResponseUri))
    Console.WriteLine("\nRequest Url : {0} was not redirected",url);   
else
    Console.WriteLine("\nRequest Url : {0} was redirected to {1}",url,myWebResponse.ResponseUri);   
// Release resources of response object.
myWebResponse.Close();

Dim ourUri As New Uri(url)
' Create a 'WebRequest' object with the specified url. 

Dim myWebRequest As WebRequest = WebRequest.Create(url)

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

' "ResponseUri" property is used to get the actual Uri from where the response was attained.
If ourUri.Equals(myWebResponse.ResponseUri) Then
    Console.WriteLine(ControlChars.Cr + "Request Url : {0} was not redirected", url)
Else
    Console.WriteLine(ControlChars.Cr + "Request Url : {0} was redirected to {1}", url, myWebResponse.ResponseUri)
End If 

' Release resources of response object.
myWebResponse.Close()

注釈

Create メソッドは、実行時にWebRequestに最も近い登録済み一致として決定されたrequestUri クラスの子孫を返します。

たとえば、 http:// または https:// で始まる URI が requestUriで渡されると、 HttpWebRequest は Createによって返されます。 代わりに、 ftp:// で始まる URI が渡された場合、 Create メソッドは FtpWebRequest インスタンスを返します。 代わりに、 file:// で始まる URI が渡された場合、 Create メソッドは FileWebRequest インスタンスを返します。

既に登録されている事前登録済みの予約の種類は次のとおりです。

  • http://

  • https://

  • ftp://

  • file://

.NET には、 http://、 https://、 ftp://、および file:// URI スキームのサポートが含まれています。 他の要求を処理するカスタム WebRequest 子孫は、 RegisterPrefix メソッドに登録されます。

Create メソッドは、requestUriString パラメーターを使用して、新しいUriに渡すWebRequest インスタンスを作成します。

Note

このメンバーは、アプリケーションでネットワーク トレースを有効にすると、トレース情報を出力します。 詳細については、「.NET Framework の Network Tracingを参照してください。

こちらもご覧ください

適用対象

Create(Uri)

ソース:
WebRequest.cs
ソース:
WebRequest.cs
ソース:
WebRequest.cs
ソース:
WebRequest.cs
ソース:
WebRequest.cs

注意事項

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.

指定した URI スキームの新しい WebRequest インスタンスを初期化します。

public:
 static System::Net::WebRequest ^ Create(Uri ^ requestUri);
public static System.Net.WebRequest Create(Uri requestUri);
[System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Net.WebRequest Create(Uri requestUri);
static member Create : Uri -> System.Net.WebRequest
[<System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member Create : Uri -> System.Net.WebRequest
Public Shared Function Create (requestUri As Uri) As WebRequest

パラメーター

requestUri
Uri

要求されたリソースの URI を含む Uri 。

返品

指定した URI スキームの WebRequest 子孫。

属性

例外

requestUriで指定された要求スキームは登録されません。

requestUri は nullです。

呼び出し元には、要求された URI または要求のリダイレクト先の URI に接続するための WebPermissionAttribute アクセス許可がありません。

例

次の例では、 Create を使用して HttpWebRequest インスタンスをインスタンス化します。 ターゲット URL を表す URI がコンストラクター パラメーターとして使用されます。

// Create a new 'Uri' object with the specified string.
Uri myUri =new Uri("http://www.contoso.com");
// Create a new request to the above mentioned URL.	
WebRequest myWebRequest= WebRequest.Create(myUri);
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse= myWebRequest.GetResponse();
' Create a new 'Uri' object with the specified string.
Dim myUri As New Uri("http://www.contoso.com")
' Create a new request to the above mentioned URL.	
Dim myWebRequest As WebRequest = WebRequest.Create(myUri)
'  Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

注釈

Create メソッドは、実行時にWebRequestに最も近い登録済み一致として決定されたrequestUri クラスの子孫を返します。

たとえば、 WebRequest 子孫 Handler1 を作成して、 http://www.contoso.com/text/ への要求を処理し、別の名前付き Handler2 を使用して http://www.contoso.com/code/への要求を処理する場合は、 Create メソッドを使用して、指定された URI に関連付けられている WebRequest 子孫を返すことができます。

URI のスキーム部分のみに基づいて WebRequest クラスの子孫を返すには、 CreateDefault メソッドを使用します。

たとえば、 http:// または https:// で始まる URI が requestUriで渡されると、 HttpWebRequest は Createによって返されます。 代わりに、 ftp:// で始まる URI が渡された場合、 Create メソッドは FileWebRequest インスタンスを返します。 代わりに、 file:// で始まる URI が渡された場合、 Create メソッドは FileWebRequest インスタンスを返します。

既に登録されている事前登録済みの予約の種類は次のとおりです。

  • http://

  • https://

  • ftp://

  • file://

.NET には、 http://、 https://、 ftp://、および file:// URI スキームのサポートが含まれています。 他の要求を処理するカスタム WebRequest 子孫は、 RegisterPrefix メソッドに登録されます。

Note

このメンバーは、アプリケーションでネットワーク トレースを有効にすると、トレース情報を出力します。 詳細については、「.NET Framework の Network Tracingを参照してください。

適用対象