WebClient.QueryString Özellik

Tanım

İstekle ilişkili sorgu adı/değer çiftleri koleksiyonunu alır veya ayarlar.

C#
public System.Collections.Specialized.NameValueCollection QueryString { get; set; }

Özellik Değeri

İstekle ilişkili sorgu adı/değer çiftlerini içeren bir NameValueCollection. İstekle ilişkili çift yoksa, değer boş bir NameValueCollectionolur.

Örnekler

Aşağıdaki kod örneği, komut satırından kullanıcı girişi alır ve QueryString özelliğine atanmış bir NameValueCollection oluşturur. Ardından yanıtı sunucudan yerel bir dosyaya indirir.

C#
string uriString = "http://www.contoso.com/search";
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Create a new NameValueCollection instance to hold the QueryString parameters and values.
NameValueCollection myQueryStringCollection = new NameValueCollection();
Console.Write("Enter the word(s), separated by space character to search for in " +  uriString + ": ");
// Read user input phrase to search for at uriString.
string searchPhrase = Console.ReadLine();
if (searchPhrase.Length > 1)
    // Assign the user-defined search phrase.
    myQueryStringCollection.Add("q",searchPhrase);
else
    // If error, default to search for 'Microsoft'.
    myQueryStringCollection.Add("q","Microsoft");		
// Assign auxilliary parameters required for the search.
Console.WriteLine("Searching " + uriString + " .......");
// Attach QueryString to the WebClient.
myWebClient.QueryString = myQueryStringCollection;
// Download the search results Web page into 'searchresult.htm' for inspection.
myWebClient.DownloadFile (uriString, "searchresult.htm");
Console.WriteLine("\nDownload of " + uriString + " was successful. Please see 'searchresult.htm' for results.");

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.

QueryString özelliği, URI'ye sorgu dizesi olarak eklenen ad/değer çiftlerini içeren bir NameValueCollection örneği içerir. QueryString özelliğinin içeriğinde bir soru işareti (?) ve ad/değer çiftleri birbirinden ve işareti (&) ayrılır.

Şunlara uygulanır

Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1