SendRequest

Description

Sends the request from the HTTPClient object to the server.

If IgnoreServerCertificate or CheckForServerCertRevocation is set to verify the server certificate, and if the verification fails, an error code will be returned.

It is not recommended to use this method to process large data (20 MB or 100,000 data rows can be considered as large data based on our tests).

Applies to

HTTPClient objects

Syntax

objectname.SendRequest ( methodName, urlName )
objectname.SendRequest ( methodName, urlName, string data )
objectname.SendRequest ( methodName, urlName, blob data )
objectname.SendRequest ( methodName, urlName, string data, encodingType )

Argument

Description

objectname

The name of the HTTPClient object from which you want to send the request.

methodName

A string value specifying the request method name, including GET, POST, PUT, DELETE, OPTIONS, TRACE, HEAD, and CONNECT.

urlName

A string value specifying the URL.

data

A blob or string value specifying the data.

encodingType (optional)

A value specifying the encoding charset of the string data to be sent: EncodingANSI!, EncodingUTF8!, EncodingUTF16LE!, or EncodingUTF16BE!.

For the string data, it will be encoded in the charset specified by the encodingType argument; if the encodingType argument is not specified, the data will be encoded in the charset specified in the Content-Type request header; if no charset is specified in the Content-Type request header, the data will be encoded in UTF-8 by default.


Return value

Integer.

Returns values as follows. If any argument's value is null, the method returns null.

1 -- Success

-1 -- General error

-2 -- Invalid URL

-3 -- Cannot connect to the Internet

-4 -- Timed out

-5 -- Code conversion failed

-6 -- Unsupported character sets

-7 -- Certification revocation checking has been enabled, but the revocation check failed to verify whether a certificate has been revoked. The server used to check for revocation might be unreachable.

-8 -- SSL certificate is invalid.

-9 -- SSL certificate was revoked.

-10 -- The function is unfamiliar with the Certificate Authority that generated the server certificate.

-11 -- SSL certificate common name (host name field) is incorrect, for example, you entered www.appeon.com and the common name on the certificate says www.demo.appeon.com.

-12 -- SSL certificate date that was received from the server is invalid. The certificate has expired.

-13 -- The certificate was not issued for the server authentication purpose.

-14 -- The application experienced an internal error when loading the SSL libraries.

-15 -- More than one type of errors when validating the server certificate.

Example 1

This example requests information from a URL using the GET method:

Integer li_rc
String ls_string
HttpClient lnv_HttpClient
lnv_HttpClient = Create HttpClient

// Sends request using GET method
li_rc = lnv_HttpClient.SendRequest("GET", "https://demo.appeon.com/PB/webapi_client/employee/102")
// Obtains the response data
if li_rc = 1 and lnv_HttpClient.GetResponseStatusCode() = 200 then
 lnv_HttpClient.GetResponseBody(ls_string)
end if

Example 2

This example sends a string query when requesting information from a URL using the POST method:

Integer li_rc
String ls_ReturnJson
HttpClient lnv_HttpClient
lnv_HttpClient = Create HttpClient

String ls_json = '{"empId":100, "fname":" John", "lname": "Guevara"}'

// Constructs a POST request (supports all headers)
lnv_HttpClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
// Content-Length header set by SendRequest

// Sends request using POST method (to add the string data to the body and set to the Content-Length header)
li_rc = lnv_HttpClient.SendRequest("POST", "https://demo.appeon.com/PB/webapi_client/employee", ls_json)

// Obtains the response data
if li_rc = 1 and lnv_HttpClient.GetResponseStatusCode() = 200 then
 lnv_HttpClient.GetResponseBody(ls_ReturnJson)
end if

Example 3

This example sends a string query in EncodingUTF8 when requesting information from a URL using the POST method:

Integer li_rc
String ls_ReturnJson
HttpClient lnv_HttpClient
lnv_HttpClient = Create HttpClient

String ls_json = '{"empId":101, "fname":" John", "lname": "Guevara"}'

// Constructs a POST request (supports all headers)
lnv_HttpClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
// Content-Length header set by SendRequest

// Sends request using POST method (to add the string data to the body and set to the Content-Length header)
li_rc = lnv_HttpClient.SendRequest("POST", " https://demo.appeon.com/PB/webapi_client/employee", ls_json, EncodingUTF8!)
// Obtains the response data
if li_rc = 1 and lnv_HttpClient.GetResponseStatusCode() = 200 then
 lnv_HttpClient.GetResponseBody(ls_ReturnJson)
end if

Example 4

This example sends a blob query when requesting information from a URL using the POST method:

Integer  li_rc
String ls_ReturnJson
HttpClient lnv_HttpClient
lnv_HttpClient = Create HttpClient
Blob lblb_data
lblb_data = Blob('{"empId":101, "fname":" John", "lname": "Guevara"}', EncodingUTF8!)

// Sends request using POST method (to add the string data to the body and set to the Content-Length header)
li_rc = lnv_HttpClient.SendRequest("POST", "https://demo.appeon.com/PB/webapi_client/employee/blob", lblb_data)

// Obtains the response data
if li_rc = 1 and lnv_HttpClient.GetResponseStatusCode() = 200 then
 lnv_HttpClient.GetResponseBody(ls_ReturnJson)
end if