Description
Use the CreateGetRequest
method to create an HTTP GET request to the specified URL. The method will return an aqHttpRequest
object describing the created request.
Note: | This method is similar to the Open method of the IWinHttpRequest interface. |
Declaration
aqHttp.CreateGetRequest(URL, User, Password)
URL | [in] | Required | String | |
User | [in] | Optional | String | |
Password | [in] | Optional | String | |
Result | The aqHttpRequest object |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameters:
URL
An absolute URL path to the resource, to which you want to send the request. Must include the protocol.
For example, https://smartbear.com or http://support.smartbear.com.
If the parameter does not include the protocol (for example, www.support.smartbear.com), the Send
method of the created aqHttpRequest
object will fail.
User
If the Basic authentication is used, the name of the user on whose behalf the request will be sent. See below.
Password
If the Basic authentication is used, the password of the user on whose behalf the request will be sent. See below.
Result Value
The aqHttpRequest
object.
Remarks
-
If your target server uses the Basic authentication, pass the user name and password as the method parameters. However, TestComplete will not send the authentication information in the first request. According to the HTTP specification, before sending the authorization header, TestComplete should receive a 401 response (Access Denied). Then TestComplete will send the authentication.
If your server requires preemptive authentication (that is, it expects the authorization header in each request) or if it responds with an unusual status code (like 400 or 403), TestComplete will not be able to send the request correctly. See the description of the
aqHttp
object to learn about possible workarounds. -
The
Send
method of theaqHttpRequest
object that the method returns will send a request without the body content, even if you pass some data as a parameter. -
If a URL, to which you send the request, includes a query parameter after the host name, put the escape character (
/
) before it:http://example.com/?param=value – Correct;
http://example.com:8080?param=value – Incorrect (no slash)
http://example.com:8080/?param=value – Correct;
http://example.com:8080?param=value – Incorrect (no slash)
http://example.com:8080/subpath?param=value – Correct (query parameters follow a resource, not the host)
http://example.com:8080/subpath/?param=value – Also correct
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://now.httpbin.org";
// Create an aqHttpRequest object
var aqHttpRequest = aqHttp.CreateGetRequest(address);
// Send the request, get an aqHttpResponse object
var aqHttpResponse = aqHttpRequest.Send();
// 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 a response body to a file
aqHttpResponse.SaveToFile("C:\\Work\\body.txt");
}
Python
def httpGetRequest():
address = "http://now.httpbin.org"
# Create an aqHttpRequest object
aqHttpRequest = aqHttp.CreateGetRequest(address)
# Send the request, get an aqHttpResponse object
aqHttpResponse = aqHttpRequest.Send()
# 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 a response body to a file
aqHttpResponse.SaveToFile("C:\\Work\\body.txt")
VBScript
Sub httpGetRequest
Dim address, aqHttpRequest, aqHttpResponse
address = "http://now.httpbin.org"
' Create an aqHttpRequest object
Set aqHttpRequest = aqHttp.CreateGetRequest(address)
' Send the request, get an aqHttpResponse object
Set aqHttpResponse = aqHttpRequest.Send()
' 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 a response body to a file
aqHttpResponse.SaveToFile("C:\\Work\\body.txt")
End Sub
DelphiScript
function httpGetRequest;
var address, aqHttpRequest, aqHttpResponse;
begin
address := 'http://now.httpbin.org';
// Create an aqHttpRequest object
aqHttpRequest := aqHttp.CreateGetRequest(address);
// Send the request, get an aqHttpResponse object
aqHttpResponse := aqHttpRequest.Send();
// 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 a response body to a file
aqHttpResponse.SaveToFile('C:\\Work\\body.txt');
end;
C++Script, C#Script
function httpGetRequest()
{
var address = "http://now.httpbin.org";
// Create an aqHttpRequest object
var aqHttpRequest = aqHttp["CreateGetRequest"](address);
// Send the request, get an aqHttpResponse object
var aqHttpResponse = aqHttpRequest["Send"]();
// 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 a response body to a file
aqHttpResponse["SaveToFile"]("C:\\Work\\body.txt");
}
See Also
aqHttp.CreatePostRequest Method
aqHttp.CreateRequest Method
aqHttp Object