WebClient.Headers Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
İstekle ilişkili üst bilgi adı/değer çiftleri koleksiyonunu alır veya ayarlar.
public:
property System::Net::WebHeaderCollection ^ Headers { System::Net::WebHeaderCollection ^ get(); void set(System::Net::WebHeaderCollection ^ value); };
public System.Net.WebHeaderCollection Headers { get; set; }
member this.Headers : System.Net.WebHeaderCollection with get, set
Public Property Headers As WebHeaderCollection
Özellik Değeri
WebHeaderCollection Bu istekle ilişkili üst bilgi adı/değer çiftleri içeren.
Örnekler
Aşağıdaki kod örneği, form verilerinin Headers gönderiye eklendiğini sunucuya bildirmek üzere application/x-www-form-urlencoded, HTTP Content-Type üst bilgisini ayarlamak için koleksiyonu kullanır.
String^ uriString;
Console::Write( "\nPlease enter the URI to post data to {for example, http://www.contoso.com}: " );
uriString = Console::ReadLine();
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
Console::WriteLine( "\nPlease enter the data to be posted to the URI {0}:", uriString );
String^ postData = Console::ReadLine();
myWebClient->Headers->Add( "Content-Type", "application/x-www-form-urlencoded" );
// Displays the headers in the request
Console::Write( "Resulting Request Headers: ");
Console::WriteLine(myWebClient->Headers);
// Apply ASCII Encoding to obtain the String^ as a Byte array.
array<Byte>^ byteArray = Encoding::ASCII->GetBytes( postData );
Console::WriteLine( "Uploading to {0} ...", uriString );
// Upload the input String* using the HTTP 1.0 POST method.
array<Byte>^responseArray = myWebClient->UploadData( uriString, "POST", byteArray );
// Decode and display the response.
Console::WriteLine( "\nResponse received was {0}",
Encoding::ASCII->GetString( responseArray ) );
string uriString;
Console.Write("\nPlease enter the URI to post data to {for example, http://www.contoso.com} : ");
uriString = Console.ReadLine();
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:",uriString);
string postData = Console.ReadLine();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");
// Display the headers in the request
Console.Write("Resulting Request Headers: ");
Console.WriteLine(myWebClient.Headers.ToString());
// Apply ASCII Encoding to obtain the string as a byte array.
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
Console.WriteLine("Uploading to {0} ...", uriString);
// Upload the input string using the HTTP 1.0 POST method.
byte[] responseArray = myWebClient.UploadData(uriString,"POST",byteArray);
// Decode and display the response.
Console.WriteLine("\nResponse received was {0}",
Encoding.ASCII.GetString(responseArray));
Dim uriString As String
Console.Write(ControlChars.Cr + "Please enter the URI to post data to{for example, http://www.contoso.com} : ")
uriString = Console.ReadLine()
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the URI {0}:", uriString)
Dim postData As String = Console.ReadLine()
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
' Display the headers in the request
Console.Write("Resulting Request Headers: ")
Console.Writeline(myWebClient.Headers.ToString())
' Apply ASCII Encoding to obtain the string as a byte array.
Dim byteArray As Byte() = Encoding.ASCII.GetBytes(postData)
Console.WriteLine("Uploading to {0} ...", uriString)
' Upload the input string using the HTTP 1.0 POST method.
Dim responseArray As Byte() = myWebClient.UploadData(uriString, "POST", byteArray)
' Decode and display the response.
Console.WriteLine(ControlChars.Cr + "Response received was :{0}", Encoding.ASCII.GetString(responseArray))
Açıklamalar
Dikkat
WebRequest, HttpWebRequest, ServicePointve WebClient kullanım dışıdır ve bunları yeni geliştirme için kullanmamalısınız. Bunun yerine HttpClient kullanın.
özelliği, Headers istekle birlikte gönderen protokol üst bilgilerini WebClient içeren bir WebHeaderCollection örnek içerir.
Bazı ortak üst bilgiler kısıtlanmış olarak kabul edilir ve sistem tarafından korunur ve bir WebHeaderCollection nesnede ayarlanamaz veya değiştirilemez. Bir nesneyle WebClient ilişkili nesnede WebHeaderCollection bu kısıtlı üst bilgilerden birini ayarlama girişimi, isteği göndermeye WebClient çalışırken daha sonra bir özel durum oluşturur.
Sistem tarafından korunan kısıtlı üst bilgiler şunlardır, ancak bunlarla sınırlı değildir:
Tarih
Ev sahibi
Ayrıca, nesne WebClient kullanılırken diğer bazı üst bilgiler de kısıtlanır. Bu kısıtlanmış üst bilgiler şunlardır ancak bunlarla sınırlı değildir:
Almak
Bağlantı
İçerik Uzunluğu
Bekleme (değer "100-devam" olarak ayarlandığında
If-Modified-Since
Aralık
Transfer-Encoding
sınıfı, HttpWebRequest yukarıdaki üst bilgilerden bazılarını ayarlamaya yönelik özelliklere sahiptir. Bir uygulamanın bu üst bilgileri ayarlaması önemliyse, HttpWebRequest sınıfı yerine WebRequest sınıfı kullanılmalıdır.
Web sunucuları ve önbellekleri bir Web isteğinde değişiklik olabileceği veya üst bilgiler ekleyebileceği için üst bilgi değerlerinin değişmeden kalacağını varsaymamalısınız.