다음을 통해 공유


WebClient.QueryString 속성

정의

요청과 연결된 쿼리 이름/값 쌍의 컬렉션을 가져오거나 설정합니다.

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

속성 값

요청과 연결된 쿼리 이름/값 쌍을 포함하는 NameValueCollection. 요청과 연결된 쌍이 없으면 값은 빈 NameValueCollection.

예제

다음 코드 예제에서는 명령줄에서 사용자 입력을 가져와서 QueryString 속성에 할당된 NameValueCollection 빌드합니다. 그런 다음 서버에서 로컬 파일로 응답을 다운로드합니다.

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."))

설명

주의

WebRequest, HttpWebRequest, ServicePointWebClient 사용되지 않으므로 새 개발에 사용하면 안 됩니다. 대신 HttpClient 사용합니다.

QueryString 속성은 URI에 쿼리 문자열로 추가되는 이름/값 쌍을 포함하는 NameValueCollection 인스턴스를 포함합니다. QueryString 속성의 내용 앞에 물음표(?)가 표시되고 이름/값 쌍은 앰퍼샌드(&)로 서로 구분됩니다.

적용 대상