GetResponseBody
PowerScript function
Description
Gets the response body into a string or blob value.
Applies to
HTTPClient and RESTClient objects
Syntax
|
1 |
objectname.GetResponseBody ( string data ) |
|
1 |
objectname.GetResponseBody ( blob data ) |
|
1 |
objectname.GetResponseBody ( string data, encodingType ) |
|
Argument |
Description |
|---|---|
|
objectname |
The name of the HTTPClient or RESTClient object for |
|
data |
A string or blob variable into which the function (For RESTClient object) If the |
|
encodingType |
A value specifying the encoding type of the string |
Return value
Integer.
Returns 1 if it succeeds and a negative value if an error occurs. If
any argument’s value is null, the method returns null.
1 — Success
-1 — General error
-7 — Failed to decompress the response body.
Example 1
This example gets the response body and converts to a blob
value:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Integer li_rc, li_StatusCode String ls_ContentType, ls_body, ls_string Blob lblb_blob 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 message if li_rc = 1 then // Obtain the response status li_StatusCode = lnv_HttpClient.GetResponseStatusCode() if li_StatusCode = 200 then // Obtain the header ls_ContentType = lnv_HttpClient.GetResponseHeader("Content-Type") // Obtain the specifid header // Obtain the response data lnv_HttpClient.GetResponseBody(ls_body) // No encoding is specified, because encoding of the response data is unknown //lnv_HttpClient.GetResponseBody(ls_string, EncodingUTF8!) // Encoding of the response data is known to be EncodingUTF8!. //lnv_HttpClient.GetResponseBody(lblb_blob) // Obtain the response data and convert to a blob ... end if end if |
Example 2
This example gets data and shows it in the DataWindow:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Integer GetResponseBody (ref string data, encoding encodingType) String ls_ResponseBody Integer li_Return RestClient lrc_GetResponseBody lrc_GetResponseBody = Create RestClient lrc_GetResponseBody.SetRequestHeader ("Content-Type", "application/json;charset=UTF-8") lrc_GetResponseBody.SendRequest ("Get", "http://demo.appeon.com/PB/webapi_client/department") li_Return = lrc_GetResponseBody.GetResponsebody ( ls_ResponseBody, EncodingUTF8! ) If li_Return <> 1 Then // Prints the error message if GetResponsebody failed Return End If If lrc_GetResponseBody.GetResponseStatusCode( ) = 200 Then // The DataWindow column name and type must match with that returned from URL: http://demo.appeon.com/PB/webapi_client/department dw_Submit.DataObject = "d_example_dept" dw_submit.importjsonbykey( ls_ResponseBody ) // Previews data in the DataWindow Else // Prints the failure message: ls_ResponseBody End If |
Example 3
The client sends the server a request which includes the “gzip”
compression method; then the server compresses and returns the data as
requested; and then the client automatically extracts the data.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Integer li_Return String ls_ReturnBody RestClient lrc_Dept lrc_Dept = Create RestClient lrc_Dept.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") // Sets the compression method in the request header lrc_Dept.SetRequestHeader("Accept-Encoding","gzip") li_Return = lrc_Dept.SendRequest("Get","https://demo.appeon.com/PB/webapi_client/department") // Return 1 indicaiting the request is sent successfully If li_Return = 1 Then li_Return = lrc_Dept.GetResponseStatusCode() If li_Return = 200 Then lrc_Dept.GetResponseBody(ls_ReturnBody) // The received data displays in the DataWindow // DataWindow column name and type must match with that in the JSON string dw_Submit.DataObject='d_example_dept' dw_Submit.Importjson( ls_ReturnBody) End If End If |
See also