WebClient.BaseAddress 속성

정의

WebClient의 요청에 대한 기본 URI를 가져오거나 설정합니다.

public:
 property System::String ^ BaseAddress { System::String ^ get(); void set(System::String ^ value); };
public string BaseAddress { get; set; }
member this.BaseAddress : string with get, set
Public Property BaseAddress As String

속성 값

String의 요청에 대한 기본 URI를 포함하는 WebClient이거나, 기본 주소를 지정하지 않은 경우 Empty입니다.

예외

BaseAddress가 잘못된 URI로 설정된 경우. 내부 예외에는 오류 위치를 찾는 데 도움이 되는 정보가 포함될 수 있습니다.

예제

다음 코드 예제에서는 인터넷 서버에서 데이터를 다운로드하고 콘솔에 표시합니다. 서버 주소(예: http://www.contoso.com)가 에 hostUri 있고 리소스 경로(예: /default.htm)가 에 있다고 uriSuffix가정합니다.

// Create a new WebClient instance.
WebClient^ myWebClient = gcnew WebClient;

// Set the BaseAddress of the Web Resource in the WebClient.
myWebClient->BaseAddress = hostUri;
Console::WriteLine( "Downloading from {0}/ {1}", hostUri, uriSuffix );
Console::WriteLine( "\nPress Enter key to continue" );
Console::ReadLine();

// Download the target Web Resource into a Byte array.
array<Byte>^ myDatabuffer = myWebClient->DownloadData( uriSuffix );

// Display the downloaded data.
String^ download = Encoding::ASCII->GetString( myDatabuffer );
Console::WriteLine( download );
Console::WriteLine( "Download of {0}{1} was successful.", myWebClient->BaseAddress, uriSuffix );
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

// Set the BaseAddress of the Web Resource in the WebClient.
myWebClient.BaseAddress = hostUri;
Console.WriteLine("Downloading from " + hostUri + "/" + uriSuffix);
Console.WriteLine("\nPress Enter key to continue");
Console.ReadLine();	

// Download the target Web Resource into a byte array.
byte[] myDatabuffer = myWebClient.DownloadData (uriSuffix);

// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDatabuffer);
Console.WriteLine(download);

Console.WriteLine("Download of " + myWebClient.BaseAddress.ToString() + uriSuffix + " was successful.");
    ' Create a new WebClient instance.
    Dim myWebClient As New WebClient()

    ' Set the BaseAddress of the Web resource in the WebClient.
    myWebClient.BaseAddress = hostUri
    Console.WriteLine(("Downloading from " + hostUri + "/" + uriSuffix))
    Console.WriteLine(ControlChars.Cr + "Press Enter key to continue")
    Console.ReadLine()

    ' Download the target Web resource into a byte array.
    Dim myDatabuffer As Byte() = myWebClient.DownloadData(uriSuffix)

    ' Display the downloaded data.
Dim download As String = Encoding.ASCII.GetString(myDatabuffer)
Console.WriteLine(download)

    Console.WriteLine(("Download of " + myWebClient.BaseAddress.ToString() + uriSuffix + " was successful."))

설명

속성에는 BaseAddress 상대 주소와 결합된 기본 URI가 포함되어 있습니다. 데이터를 업로드하거나 다운로드하는 메서드를 호출할 때 개체는 WebClient 이 기본 URI를 메서드 호출에서 지정한 상대 주소와 결합합니다. 절대 URI WebClient 를 지정하는 경우 는 속성 값을 사용하지 BaseAddress 않습니다.

이전에 설정된 값을 제거하려면 이 속성을 null 또는 빈 문자열("")로 설정합니다.

적용 대상