HttpWebResponse.GetResponseHeader(String) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
응답과 함께 반환된 헤더 내용을 가져옵니다.
public:
System::String ^ GetResponseHeader(System::String ^ headerName);
public string GetResponseHeader (string headerName);
member this.GetResponseHeader : string -> string
Public Function GetResponseHeader (headerName As String) As String
매개 변수
- headerName
- String
반환할 헤더 값입니다.
반환
지정된 헤더의 내용입니다.
예외
현재 인스턴스가 삭제된 경우
예제
이 예제에서는 웹 요청을 만들고 응답에 대한 쿼리를 만듭니다. 사이트에 인증이 필요한 경우 이 예제는 챌린지 문자열로 응답합니다. 이 문자열은 를 사용하여 GetResponseHeader추출됩니다.
void GetPage( String^ url )
{
try
{
Uri^ ourUri = gcnew Uri( url );
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( ourUri ) );
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
Console::WriteLine( "\nThe server did not issue any challenge. Please try again with a protected resource URL." );
// Releases the resources of the response.
myHttpWebResponse->Close();
}
catch ( WebException^ e )
{
HttpWebResponse^ response = (HttpWebResponse^)( e->Response );
if ( response != nullptr )
{
if ( response->StatusCode == HttpStatusCode::Unauthorized )
{
String^ challenge = nullptr;
challenge = response->GetResponseHeader( "WWW-Authenticate" );
if ( challenge != nullptr )
Console::WriteLine( "\nThe following challenge was raised by the server: {0}", challenge );
}
else
{
Console::WriteLine( "\nThe following WebException was raised : {0}", e->Message );
}
}
else
{
Console::WriteLine( "\nResponse Received from server was 0" );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "\nThe following Exception was raised : {0}", e->Message );
}
}
public static void GetPage(String url)
{
try
{
Uri ourUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(ourUri);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Console.WriteLine("\nThe server did not issue any challenge. Please try again with a protected resource URL.");
// Releases the resources of the response.
myHttpWebResponse.Close();
}
catch(WebException e)
{
HttpWebResponse response = (HttpWebResponse)e.Response;
if (response != null)
{
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
string challenge = null;
challenge= response.GetResponseHeader("WWW-Authenticate");
if (challenge != null)
Console.WriteLine("\nThe following challenge was raised by the server:{0}",challenge);
}
else
{
Console.WriteLine("\nThe following WebException was raised : {0}",e.Message);
}
}
else
{
Console.WriteLine("\nResponse Received from server was null");
}
}
catch(Exception e)
{
Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
}
}
}
Public Shared Sub GetPage(url As [String])
Try
Dim ourUri As New Uri(url)
' Creates an HttpWebRequest for the specified URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(ourUri), HttpWebRequest)
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Console.WriteLine(ControlChars.NewLine + "The server did not issue any challenge. Please try again with a protected resource URL.")
' Releases the resources of the response.
myHttpWebResponse.Close()
Catch e As WebException
Dim response As HttpWebResponse = CType(e.Response, HttpWebResponse)
If Not (response Is Nothing) Then
If response.StatusCode = HttpStatusCode.Unauthorized Then
Dim challenge As String = Nothing
challenge = response.GetResponseHeader("WWW-Authenticate")
If Not (challenge Is Nothing) Then
Console.WriteLine(ControlChars.NewLine + "The following challenge was raised by the server:{0}", challenge)
End If
Else
Console.WriteLine(ControlChars.NewLine + "The following exception was raised : {0}", e.Message)
End If
Else
Console.WriteLine(ControlChars.NewLine + "Response Received from server was null")
End If
Catch e As Exception
Console.WriteLine(ControlChars.NewLine + "The following exception was raised : {0}", e.Message)
End Try
End Sub
설명
를 사용하여 GetResponseHeader 특정 헤더의 콘텐츠를 검색합니다. 반환할 헤더를 지정해야 합니다.
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET