次の方法で共有


NetworkCredential.GetCredential メソッド

指定した URI と認証の種類用に NetworkCredential クラスのインスタンスを返します。

Public Overridable Function GetCredential( _
   ByVal uri As Uri, _   ByVal authType As String _) As NetworkCredential Implements ICredentials.GetCredential
[C#]
public virtual NetworkCredential GetCredential(Uriuri,stringauthType);
[C++]
public: virtual NetworkCredential* GetCredential(Uri* uri,String* authType);
[JScript]
public function GetCredential(
   uri : Uri,authType : String) : NetworkCredential;

パラメータ

戻り値

NetworkCredential のインスタンス。

実装

ICredentials.GetCredential

使用例

[Visual Basic, C#, C++] GetCredential メソッドを使用して、指定した URI の NetworkCredential インスタンスを取得する例を次に示します。

 
' Create an empty instance of the NetworkCredential class.
Dim myCredentials As New NetworkCredential(userName, password)
' Create a WebRequest with the specified URL. 
Dim myWebRequest As WebRequest = WebRequest.Create(url)
' GetCredential returns the same NetworkCredential instance that invoked it, 
' irrespective of what parameters were provided to it. 
 myWebRequest.Credentials = myCredentials.GetCredential(New Uri(url), "")
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "User Credentials:- UserName : {0} , Password : {1}", myCredentials.UserName, myCredentials.Password)
' Send the request and wait for a response.
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "Request to Url is sent.Waiting for response...Please wait ...")
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
' Process the response.
Console.WriteLine(ControlChars.Cr + "Response received sucessfully")
' Release the resources of the response object.
myWebResponse.Close()

[C#] 
// Create an empty instance of the NetworkCredential class.
NetworkCredential myCredentials = new NetworkCredential(userName,password);
// Create a webrequest with the specified URL. 
WebRequest myWebRequest = WebRequest.Create(url); 
myWebRequest.Credentials = myCredentials.GetCredential(new Uri(url),"");
Console.WriteLine("\n\nUser Credentials:- UserName : {0} , Password : {1}",myCredentials.UserName,myCredentials.Password);
// Send the request and wait for a response.
Console.WriteLine("\n\nRequest to Url is sent.Waiting for response...Please wait ...");
WebResponse myWebResponse = myWebRequest.GetResponse();
// Process the response.
   Console.WriteLine("\nResponse received sucessfully");
// Release the resources of the response object.
myWebResponse.Close();

[C++] 
// Create an empty instance of the NetworkCredential class.
NetworkCredential* myCredentials =
   new NetworkCredential(userName, password);
// Create a webrequest with the specified URL.
WebRequest* myWebRequest = WebRequest::Create(url);
myWebRequest->Credentials =
   myCredentials->GetCredential(new Uri(url), S"");
Console::WriteLine(S"\n\nUser Credentials:- UserName : {0} , Password : {1}",
   myCredentials->UserName, myCredentials->Password);
// Send the request and wait for a response.
Console::WriteLine(S"\n\nRequest to Url is sent.Waiting for response...Please wait ...");
WebResponse* myWebResponse =
   myWebRequest->GetResponse();
// Process the response.
Console::WriteLine(S"\nResponse received sucessfully");
// Release the resources of the response object.
myWebResponse->Close();

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

NetworkCredential クラス | NetworkCredential メンバ | System.Net 名前空間