Description
Sends the HTTP PATCH request to the server and then gets the content of the server response. It does not parse the HTTP response code and content of the server response.
It is NOT supported 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
Syntax
objectname.SendPatchRequest(string urlName, string data, ref string response)
Argument |
Description |
---|---|
objectname |
The name of the RESTClient object from which you want to send the request. |
urlName |
A string value specifying the URL. |
data |
A string value specifying the data to send. If the user sets the encoding charset in the Content-Type request header, this function will encode the data with the specified charset; if charset is not specified, this function will encode the data in UTF-8 by default. |
response |
The content of the server response. If RESTClient failed to send request or server provides no response, the response value is an empty string. If the response value is compressed as gzip, it will be automatically decompressed. Only gzip compression format is supported at this moment. If the server specified the Content-Type response header, and in which the encoding charset is specified, this function will encode the data with the specified charset; if charset is not specified, this function will encode the data in UTF-8 by default. |
Return value
Integer. Returns 1 if the function 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.
-2 -- Invalid URL.
-3 -- Cannot connect to the Internet.
-4 -- Timeout.
-7 -- Failed to decompress data.
-10 -- The token is invalid or has expired.
-14 -- Code conversion failed.
-15 -- Unsupported character set.
-18 -- 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.
-19 -- SSL certificate is invalid.
-20 -- SSL certificate was revoked.
-21 -- The function is unfamiliar with the Certificate Authority that generated the server's certificate.
-22 -- SSL certificate common name (host name field) is incorrect, for example, if you entered www.appeon.com and the common name on the certificate says www.devmagic.com.
-23 -- SSL certificate date that was received from the server is bad. The certificate has expired.
-24 -- The certificate was not issued for the server authentication purpose.
-25 -- The application experienced an internal error loading the SSL libraries.
-26 -- More than one type of errors when validating the server certificate.
-27 -- The server requires the client to provide a certificate.
-28 -- The client certificate has not been assigned with a private key.
-29 -- The client certificate has no accessible private key.
-30 -- Cannot find the specified certificate.
-31 -- Failed to read the certificate.
-32 -- The certificate password is wrong.
-33 -- TLS 1.3 error. The client does not support TLS 1.3.
-34 -- Response is unrecognizable. Normally this is because the HTTP version does not match with the version required by the server.
-35 -- TLS 1.3 error. The server does not support TLS 1.3.
Example
The following example submits the new value of the current row in DataWindow to server and then returns the updated value.
RestClient lrc_P023 String ls_P023_Response Integer li_P023_SendReturn,li_P023_GetTokenReturn String ls_P023_Token,ls_P023_SendData lrc_P023 = Create RestClient //Sets the token parameters TokenRequest ltreq_P023_Appeon ltreq_P023_Appeon.tokenlocation = "https://demo.appeon.com/pb/identityserver/connect/token" ltreq_P023_Appeon.method = "post" ltreq_P023_Appeon.GrantType = "password" ltreq_P023_Appeon.ClientId = "P0VRQ-ddHn/WWd6lcCNJbaO9ny-JCNHirDJkHNgZ0-M=" ltreq_P023_Appeon.ClientSecret = "K7gNU3sdo-OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=" ltreq_P023_Appeon.UserName = "TestUser" ltreq_P023_Appeon.PassWord = "TestPassword" //Gets token via RESTClient li_P023_GetTokenReturn = lrc_P023.GetOauthtoken( ltreq_P023_Appeon, ls_P023_Token) If li_P023_GetTokenReturn = 1 Then lrc_P023.SetRequestHeaders( "Content-Type:application/json;charset=UTF-8~r~nAccept-Encoding:gzip" ) lrc_P023.SetOauthToken( ls_P023_Token ) //Sets authentication lrc_P023.Retrieve( dw_Data, "https://demo.appeon.com/PB/webapi_client/api/department/retrieve") //Modifies the column data in DataWindow If dw_Data.GetRow() > 0 Then dw_Data.SetItem(dw_Data.GetRow(), 2, "Test send patch request"+String(rand(100))) //..... //Exports the modified row to DataWindow JSON string ls_P023_SendData = dw_Data.Exportjson( Primary!, dw_Data.GetRow(),dw_Data.GetRow(), True) //Updates data via the following URL and returns the updated data row li_P023_SendReturn=lrc_P023.SendPatchRequest("https://demo.appeon.com/PB/webapi_client/api/department/update/modelentry", ls_P023_SendData, ls_P023_Response) If li_P023_SendReturn <> 1 Or lrc_P023.GetResponseStatusCode() <> 200 Then //Checks if any error information and checks the responsebody: ls_P023_Response End If //Imports the returned data row to DataWindow dw_Data.ImportRowFromJson(ls_P023_Response,0) End If Else //Checks if any failure message End If
See also