Description
Sends the request from the HTTP client object to the server.
Applies to
HTTPClient object
Syntax
objectname.SendRequest ( methodName, urlName )
objectname.SendRequest ( methodName, urlName, data )
objectname.SendRequest ( methodName, urlName, 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. The string data will be converted to EncodingUTF8! if no encoding value is specified. |
|
encodingType |
An encoding value specifying which format the string data to be converted to. |
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
Example 1
This example requests information from an URL using the GET method:
Integer li_rc
String ls_string
HttpClient lnv_HttpClient
lnv_HttpClient = Create HttpClient
// send request using GET method
li_rc = lnv_HttpClient.SendRequest("GET", "http://demo.appeon.com/PB/webapi_client/employee/102")
// obtain 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 an 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"}'
// Construct a POST request (supports all headers)
lnv_HttpClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
// Content-Length header set by SendRequest
// Send 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", "http://demo.appeon.com/PB/webapi_client/employee", ls_json)
// obtain 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 an 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"}'
// Construct a POST request (supports all headers)
lnv_HttpClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
// Content-Length header set by SendRequest
// Send 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", " http://demo.appeon.com/PB/webapi_client/employee", ls_json, EncodingUTF8!)
// obtain 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 an URL using the PUT 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"}')
// Send request using PUT method (to add the string data to the body and set to the Content-Length header)
li_rc = lnv_HttpClient.SendRequest("PUT", "http://demo.appeon.com/PB/webapi_client/employee", lblb_data)
// obtain the response data
if li_rc = 1 and lnv_HttpClient.GetResponseStatusCode() = 200 then
lnv_HttpClient.GetResponseBody(ls_ReturnJson)
end if


