Bagikan melalui


WebRequest.PreAuthenticate Properti

Definisi

Saat ditimpa di kelas turunan, menunjukkan apakah akan melakukan pra-autentikasi permintaan.

public:
 virtual property bool PreAuthenticate { bool get(); void set(bool value); };
public virtual bool PreAuthenticate { get; set; }
member this.PreAuthenticate : bool with get, set
Public Overridable Property PreAuthenticate As Boolean

Nilai Properti

true untuk melakukan pra-autentikasi; jika tidak, false.

Pengecualian

Setiap upaya dilakukan untuk mendapatkan atau mengatur properti, ketika properti tidak ditimpa di kelas turunan.

Contoh

Contoh berikut mengatur properti PreAuthenticate ke true sehingga NetworkCredential yang disimpan di properti Credentials akan dikirim bersama dengan permintaan sumber daya.

// Create a new webrequest to the mentioned URL.
WebRequest^ myWebRequest = WebRequest::Create( url );

// Set 'Preauthenticate' property to true. Credentials will be sent with the request.
myWebRequest->PreAuthenticate = true;

Console::WriteLine( "\nPlease enter your credentials for the requested Url" );
Console::WriteLine( "UserName" );
String^ UserName = Console::ReadLine();
Console::WriteLine( "Password" );
String^ Password = Console::ReadLine();

// Create a New 'NetworkCredential' object.
NetworkCredential^ networkCredential = gcnew NetworkCredential( UserName,Password );

// Associate the 'NetworkCredential' object with the 'WebRequest' object.
myWebRequest->Credentials = networkCredential;

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Create a new webrequest to the mentioned URL.
WebRequest myWebRequest=WebRequest.Create(url);

// Set 'Preauthenticate'  property to true.  Credentials will be sent with the request.
myWebRequest.PreAuthenticate=true;

Console.WriteLine("\nPlease enter your credentials for the requested Url");
Console.WriteLine("UserName");
string UserName=Console.ReadLine();
Console.WriteLine("Password");
string Password=Console.ReadLine();

// Create a New 'NetworkCredential' object.
NetworkCredential networkCredential=new NetworkCredential(UserName,Password);

// Associate the 'NetworkCredential' object with the 'WebRequest' object.
myWebRequest.Credentials=networkCredential;

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse=myWebRequest.GetResponse();

' Create a new webrequest to the mentioned URL.
Dim myWebRequest As WebRequest = WebRequest.Create(url)

' Set 'Preauthenticate'  property to true.
myWebRequest.PreAuthenticate = True
Console.WriteLine(ControlChars.Cr + "Please enter your credentials for the requested Url")
Console.WriteLine("UserName")
Dim UserName As String = Console.ReadLine()
Console.WriteLine("Password")
Dim Password As String = Console.ReadLine()

' Create a New 'NetworkCredential' object.
Dim networkCredential As New NetworkCredential(UserName, Password)

' Associate the 'NetworkCredential' object with the 'WebRequest' object.
myWebRequest.Credentials = networkCredential

' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

Keterangan

Hati

WebRequest, HttpWebRequest, ServicePoint, dan WebClient usang, dan Anda tidak boleh menggunakannya untuk pengembangan baru. Gunakan HttpClient sebagai gantinya.

Dengan pengecualian permintaan pertama, properti PreAuthenticate menunjukkan apakah akan mengirim informasi autentikasi dengan permintaan berikutnya tanpa menunggu untuk ditantang oleh server. Saat PreAuthenticatefalse, WebRequest menunggu tantangan autentikasi sebelum mengirim informasi autentikasi.

Nota

Kelas WebRequest adalah kelas abstract. Perilaku aktual instans WebRequest pada run time ditentukan oleh kelas turunan yang dikembalikan oleh metode WebRequest.Create. Untuk informasi selengkapnya tentang nilai dan pengecualian default, lihat dokumentasi untuk kelas turunan, seperti HttpWebRequest dan FileWebRequest.

Berlaku untuk

Lihat juga