HttpListenerRequest.Url 속성

정의

클라이언트에서 요청한 Uri 개체를 가져옵니다.

public:
 property Uri ^ Url { Uri ^ get(); };
public Uri? Url { get; }
public Uri Url { get; }
member this.Url : Uri
Public ReadOnly Property Url As Uri

속성 값

Uri

클라이언트에서 요청한 리소스를 식별하는 Uri입니다.

예제

다음 코드 예제는 Url 속성입니다.

public static void ShowRequestProperties1 (HttpListenerRequest request)
{
    // Display the MIME types that can be used in the response.
    string[] types = request.AcceptTypes;
    if (types != null)
    {
        Console.WriteLine("Acceptable MIME types:");
        foreach (string s in types)
        {
            Console.WriteLine(s);
        }
    }
    // Display the language preferences for the response.
    types = request.UserLanguages;
    if (types != null)
    {
        Console.WriteLine("Acceptable natural languages:");
        foreach (string l in types)
        {
            Console.WriteLine(l);
        }
    }

    // Display the URL used by the client.
    Console.WriteLine("URL: {0}", request.Url.OriginalString);
    Console.WriteLine("Raw URL: {0}", request.RawUrl);
    Console.WriteLine("Query: {0}", request.QueryString);

    // Display the referring URI.
    Console.WriteLine("Referred by: {0}", request.UrlReferrer);

    //Display the HTTP method.
    Console.WriteLine("HTTP Method: {0}", request.HttpMethod);
    //Display the host information specified by the client;
    Console.WriteLine("Host name: {0}", request.UserHostName);
    Console.WriteLine("Host address: {0}", request.UserHostAddress);
    Console.WriteLine("User agent: {0}", request.UserAgent);
}
Public Shared Sub ShowRequestProperties1(ByVal request As HttpListenerRequest)
    ' Display the MIME types that can be used in the response.
    Dim types As String() = request.AcceptTypes

    If types IsNot Nothing Then
        Console.WriteLine("Acceptable MIME types:")

        For Each s As String In types
            Console.WriteLine(s)
        Next
    End If

    ' Display the language preferences for the response.
    types = request.UserLanguages

    If types IsNot Nothing Then
        Console.WriteLine("Acceptable natural languages:")

        For Each l As String In types
            Console.WriteLine(l)
        Next
    End If

    ' Display the URL used by the client.
    Console.WriteLine("URL: {0}", request.Url.OriginalString)
    Console.WriteLine("Raw URL: {0}", request.RawUrl)
    Console.WriteLine("Query: {0}", request.QueryString)

    ' Display the referring URI.
    Console.WriteLine("Referred by: {0}", request.UrlReferrer)

    ' Display the HTTP method.
    Console.WriteLine("HTTP Method: {0}", request.HttpMethod)

    ' Display the host information specified by the client.
    Console.WriteLine("Host name: {0}", request.UserHostName)
    Console.WriteLine("Host address: {0}", request.UserHostAddress)
    Console.WriteLine("User agent: {0}", request.UserAgent)
End Sub

설명

속성을 Url 사용하면 개체에서 Uri 사용할 수 있는 모든 정보를 가져올 수 있습니다. URI 요청의 원시 텍스트만 알아야 하는 경우 대신 속성을 사용하는 RawUrl 것이 좋습니다.

클라이언트에서 를 Uri 구문 분석할 수 없는 경우 속성은 Url null입니다.

UnescapeRequestUrl 경우 속성 나타냅니다 HttpListener 는 백분율로 인코딩된 값 변환 되 고 다른 정규화 단계에 따라 변환 된 URI 대신 이스케이프 되지 않은 원시 URI를 사용 합니다.

경우는 HttpListener 인스턴스를 통해 요청을 수신 합니다 http.sys 제공한 URI 문자열의 인스턴스를 만들고 서비스를 http.sys,으로 노출를 HttpListenerRequest.Url 속성.

http.sys 서비스는 두 요청 URI 문자열을 노출 합니다.

  • 원시 URI

  • 변환 된 URI

원시 URI가는 System.Uri HTTP 요청의 요청 줄에 제공 합니다.

GET /path/

Host: www.contoso.com

제공 된 URI의 원시 http.sys 위에서 언급 한 요청에 "경로 /"입니다. 이 네트워크를 통해 전송 된 HTTP 동사를 다음 문자열을 나타냅니다.

서비스는 http.sys HTTP 요청 줄에 제공된 URI 및 호스트 헤더를 사용하여 요청에 제공된 정보에서 변환된 URI를 만들어 요청을 전달해야 하는 원본 서버를 결정합니다. 이 등록 된 URI 접두사를 사용 하 여 요청에서 정보를 비교 하 여 이루어집니다. 이러한 값을 비교할 수 있도록 요청과 일부 정규화를 수행해야 합니다. 변환 된 URI 위의 샘플은 다음과 같을 수 됩니다.

http://www.contoso.com/path/

합니다 http.sys 결합 서비스는 Uri.Host 속성 값과 문자열을 변환된 된 URI를 만드는 요청 줄에 있습니다. 또한 http.sys 하며 System.Uri 클래스는 또한 다음을 수행 합니다.

  • 이스케이프 해제 인코딩된 모든 백분율 값입니다.

  • Utf-16 문자 표현으로 변환 백분율로 인코딩된 비 ASCII 문자입니다. 유니코드 문자 (유니코드 %uXXXX 형식을 사용 하 여 인코딩) 및 u t F-8과 ANSI/DBCS 문자는 사용할 수는 note 합니다.

  • 경로 압축 등의 다른 정규화 단계를 실행합니다.

백분율로 인코딩된 값에 사용 되는 인코딩에 대 한 정보가 요청 없으므로 백분율로 인코딩된 값을 구문 분석 하 여 올바른 인코딩을 결정 못할 수 있습니다.

따라서 http.sys 프로세스를 수정 하는 것에 대 한 두 개의 레지스트리 키를 제공 합니다.

레지스트리 키 기본값 설명
EnableNonUTF8 1 0 이면 http.sys u t F-8로 인코딩된 Url만 허용 합니다.

0이 아닌 경우 http.sys 도 요청에서 ANSI로 인코딩된 또는 DBCS 인코딩된 Url을 허용 합니다.
FavorUTF8 1 0이 아닌 경우 http.sys 디코딩할 URL u t F-8로 먼저 해당 변환에 실패 이며 EnableNonUTF8 0이 아닌 경우 항상 시도 차례로 Http.sys을 ANSI 또는 DBCS 디코딩해야 하는 작업을 하려고 합니다.

0 (그리고 EnableNonUTF8 0이 아닌 경우) http.sys 있는지을 ANSI 또는 DBCS; 디코딩 하려고 성공 하면를 u t F-8로 변환 하려고 합니다.

HttpListener 요청이 수신에서 변환 된 URI를 사용 하 여 http.sys 대 한 입력으로 Url 속성입니다.

Uri에서 문자 및 숫자 이외의 문자를 지원할 필요가 있습니다. 예로 고객에 대 한 고객 정보를 검색 하는 데 사용 되는 다음 URI를 "1/3812" 번호:

http://www.contoso.com/Customer('1%2F3812')/

Uri (%2F)의 백분율로 인코딩된 슬래시를 note 합니다. 이것이 필요 하므로 경우 슬래시 문자 데이터 및 경로 구분 기호가 아니라입니다.

Uri 생성자에 문자열을 전달에 다음 URI를 일으킵니다.

http://www.contoso.com/Customer('1/3812')/

경로를 세그먼트로 분한 다음 요소에 만들어집니다.

Customer('1

3812')

요청을 보낸 사람의 의도 아닙니다.

경우는 UnescapeRequestUrl 속성이 false로 설정 됩니다 때 합니다 HttpListener 요청이 수신 원시 URI를 사용 하 여 변환 된 URI 대신 http.sys 대 한 입력으로 Url 속성입니다.

적용 대상

추가 정보