WebClient.QueryString WebClient.QueryString WebClient.QueryString WebClient.QueryString Property

Definition

Ruft eine Auflistung der Name-Wert-Paare für Abfragen auf, die der Anforderung zugeordnet sind, oder legt diese fest.Gets or sets a collection of query name/value pairs associated with the request.

public:
 property System::Collections::Specialized::NameValueCollection ^ QueryString { System::Collections::Specialized::NameValueCollection ^ get(); void set(System::Collections::Specialized::NameValueCollection ^ value); };
public System.Collections.Specialized.NameValueCollection QueryString { get; set; }
member this.QueryString : System.Collections.Specialized.NameValueCollection with get, set
Public Property QueryString As NameValueCollection

Eigenschaftswert

Eine NameValueCollection mit den der Anforderung zugeordneten Name-Wert-Paaren für Abfragen.A NameValueCollection that contains query name/value pairs associated with the request. Wenn der Anforderung keine Paare zugeordnet sind, ist der Wert eine leere NameValueCollection.If no pairs are associated with the request, the value is an empty NameValueCollection.

Beispiele

Im folgenden Codebeispiel wird erhält Benutzereingaben über die Befehlszeile und erstellt eine NameValueCollection , zugewiesen ist die QueryString Eigenschaft.The following code example takes user input from the command line and builds a NameValueCollection that is assigned to the QueryString property. Es werden dann die Antwort vom Server in eine lokale Datei heruntergeladen.It then downloads the response from the server to a local file.

String^ uriString = "http://www.contoso.com/search";
// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;
// Create a new NameValueCollection instance to hold the QueryString parameters and values.
NameValueCollection^ myQueryStringCollection = gcnew NameValueCollection;
Console::Write( "Enter the word(s), separated by space character to search for in {0}: ", 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 {0} .......", 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 {0} was successful. Please see 'searchresult.htm' for results.", uriString );
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.");
Dim uriString As String = "http://www.contoso.com/search"
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Create a new NameValueCollection instance to hold the QueryString parameters and values.
Dim myQueryStringCollection As New NameValueCollection()
Console.Write(("Enter the word(s), separated by space characters, to search for in " + uriString + ": "))
' Read user input phrase to search in uriString.
Dim searchPhrase As String = Console.ReadLine()
If searchPhrase.Length > 1 Then
    'Assign the user-defined search phrase.
    myQueryStringCollection.Add("q", searchPhrase)
' If error, default to search 'Microsoft'.
Else
    myQueryStringCollection.Add("q", "Microsoft")
End If 
' 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((ControlChars.Cr + "Download of " + uriString + " was successful. Please see 'searchresult.htm' for results."))

Hinweise

Die QueryString Eigenschaft enthält eine NameValueCollection -Instanz mit Name/Wert-Paare, die den URI als Abfragezeichenfolge angefügt sind.The QueryString property contains a NameValueCollection instance containing name/value pairs that are appended to the URI as a query string. Den Inhalt der QueryString Eigenschaft durch ein Fragezeichen (?) vorangestellt werden, und die Name/Wert-Paare werden durch ein kaufmännisches und-Zeichen voneinander getrennt (&).The contents of the QueryString property are preceded by a question mark (?), and name/value pairs are separated from one another by an ampersand (&).

Gilt für: