aqHttpResponse.GetHeader Method

Applies to TestComplete 15.40, last modified on July 05, 2022

Description

Use the GetHeader method to retrieve the value of a specific header of an HTTP response returned by the aqHttpRequest.Send method.

Note: This method is identical to the GetResponseHeader method of the IWinHttpRequest interface.

Declaration

aqHttpResponse.GetHeader(Header)

Header [in]    Required    String    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Header

The name of the header whose value you want to get. The parameter is case-insensitive.

Result Value

The value of the specified HTTP response header.

Remarks

  • This method can be run only after successful completion of the Send method call.

  • For a full list of headers you can get with this method, see the value of the AllHeaders property.

Example

The example below demonstrates how you can use the aqHttp object to create an HTTP GET request and send it to get a response from the server. To work with the created request, the code uses the aqHttpRequest object. To work with the server response, the sample code uses the aqHttpResponse object:

JavaScript, JScript

function httpGetRequest()
{
  var address = "http://httpbin.org";

  // Create an aqHttpRequest object
  var aqHttpRequest = aqHttp.CreateGetRequest(address);

  // Send the request, get an aqHttpResponse object
  var aqHttpResponse = aqHttpRequest.Send();

  if (aqHttpResponse != null)
  {
    // Read the response data
    Log.Message(aqHttpResponse.AllHeaders); // All headers
    Log.Message(aqHttpResponse.GetHeader("Content-Type")); // A specific header
    Log.Message(aqHttpResponse.StatusCode); // A status code
    Log.Message(aqHttpResponse.StatusText); // A status text
    Log.Message(aqHttpResponse.Text); // A response body
    
    // Save the response body to a file and place it to the project folder
    aqHttpResponse.SaveToFile(Project.Path + "body.txt");
  }
}

Python

def httpGetRequest():
  address = "http://httpbin.org"

  # Create an aqHttpRequest object
  aqHttpRequest = aqHttp.CreateGetRequest(address)

  # Send the request, get an aqHttpResponse object
  aqHttpResponse = aqHttpRequest.Send()

  if aqHttpResponse != None:
    # Read the response data
    Log.Message(aqHttpResponse.AllHeaders) # All headers
    Log.Message(aqHttpResponse.GetHeader("Content-Type")) # A specific header
    Log.Message(aqHttpResponse.StatusCode) # A status code
    Log.Message(aqHttpResponse.StatusText) # A status text
    Log.Message(aqHttpResponse.Text) # A response body
    
    # Save the response body to a file and place it to the project folder
    aqHttpResponse.SaveToFile(Project.Path + "body.txt")

VBScript

Sub httpGetRequest
  Dim address, aqHttpRequest, aqHttpResponse
  address = "http://httpbin.org"

  ' Create an aqHttpRequest object
  Set aqHttpRequest = aqHttp.CreateGetRequest(address)

  ' Send the request, get an aqHttpResponse object
  Set aqHttpResponse = aqHttpRequest.Send()

  If Not aqHttpResponse Is Nothing Then
    ' Read the response data
    Log.Message(aqHttpResponse.AllHeaders) ' All headers
    Log.Message(aqHttpResponse.GetHeader("Content-Type")) ' A specific header
    Log.Message(aqHttpResponse.StatusCode) ' A status code
    Log.Message(aqHttpResponse.StatusText) ' A status text
    Log.Message(aqHttpResponse.Text) ' A response body

    ' Save the response body to a file and place it to the project folder
    aqHttpResponse.SaveToFile(Project.Path & "body.txt")
  End If
End Sub

DelphiScript

function httpGetRequest;
var address, aqHttpRequest, aqHttpResponse;
begin
  
  address := 'http://httpbin.org';

  // Create an aqHttpRequest object
  aqHttpRequest := aqHttp.CreateGetRequest(address);

  // Send the request, get an aqHttpResponse object
  aqHttpResponse := aqHttpRequest.Send();

  if aqHttpResponse <> nil then
    begin
    // Read the response data
    Log.Message(aqHttpResponse.AllHeaders); // All headers
    Log.Message(aqHttpResponse.GetHeader('Content-Type')); // A specific header
    Log.Message(aqHttpResponse.StatusCode); // A status code
    Log.Message(aqHttpResponse.StatusText); // A status text
    Log.Message(aqHttpResponse.Text); // A response body

    // Save the response body to a file and place it to the project folder
    aqHttpResponse.SaveToFile(Project.Path + 'body.txt');
  end;
end;

C++Script, C#Script

function httpGetRequest()
{
  var address = "http://httpbin.org";

  // Create an aqHttpRequest object
  var aqHttpRequest = aqHttp["CreateGetRequest"](address);

  // Send the request, get an aqHttpResponse object
  var aqHttpResponse = aqHttpRequest["Send"]();

  if (aqHttpResponse != null)
  {
    // Read the response data
    Log["Message"](aqHttpResponse["AllHeaders"]); // All headers
    Log["Message"](aqHttpResponse["GetHeader"]("Content-Type")); // A specific header
    Log["Message"](aqHttpResponse["StatusCode"]); // A status code
    Log["Message"](aqHttpResponse["StatusText"]); // A status text
    Log["Message"](aqHttpResponse["Text"]); // A response body
    
    // Save the response body to a file and place it to the project folder
    aqHttpResponse["SaveToFile"](Project["Path"] + "body.txt");
  }
}

See Also

SaveToFile Method
aqHttpResponse Object

Highlight search results