PatchData Method  
 

Submits patch data to the server and returns the result in a string buffer provided by the caller.

Syntax

object.PatchData( Resource, PatchData, Buffer, [Options] )

Parameters

Resource
A string that specifies the resource that the patch data will be submitted to. Typically this is the name of an executable script.
PatchData
A string that contains the patch information. Typically this is XML or JSON formatted data which contains the information that should be used to update the specified resource.
Buffer
A string or byte array that will contain the output generated by the script. Typically this is XML or JSON content which is generated by the script as a result of processing the data that was posted to it.
Options
An optional integer value which specifies one or more options. This argument is constructed by using a bitwise operator with any of the following values:
Value Constant Description
0 httpPatchDefault The default post mode. The contents of the buffer are encoded and sent as standard form data. The data returned by the server is copied to the result buffer exactly as it is returned from the server.
1 httpPatchConvert If the data being returned from the server is textual, it is automatically converted so that the end of line character sequence is compatible with the Windows platform. Individual carriage return or linefeed characters are converted to carriage return/linefeed character sequences. Note that this option does not have any effect on the form data being submitted to the server, only on the data returned by the server.
4 httpPatchErrorData This option causes the client to accept error data from the server if the request fails. If this option is specified, an error response from the server will not cause the method to fail. Instead, the response is returned to the client and the method will succeed.

Return Value

A value of zero is returned if the operation was successful, otherwise a non-zero error code is returned which indicates the cause of the failure.

Remarks

The PatchData method is used to submit XML or JSON formatted patch data to a service, and then returns a copy of the response from the server into a local string buffer. This method will not perform any encoding and will not automatically define the type of patch data being submitted. Your application is responsible for specifying the content type for the patch data, and ensuring that the XML or JSON data that is being submitted to the server is formatted correctly.

This method sends a PATCH command to the server, which is similar to a POST or PUT request. It is used to make partial updates to a resource, rather than creating or replacing it entirely. The format of the patch data is specific to the service being used. If the resource being patched does not exist, the behavior is defined by the server. If enough information is provided, it may choose to create the resource just as if a PUT command was used, or it may return an error.

Your application should use the SetHeader method to define the Content-Type header prior to calling the PatchData method. One of the most common formats used is the JSON Merge Patch which is defined in RFC 7396. The value for the Content-Type header for this patch format is "application/merge-patch+json". Refer to your service API documentation to determine what patch formats are acceptable, along with any additional header values that must be defined.

When encountering a server error during a request, the PatchData method normally returns an error code, and no data is copied into the caller-provided buffer. The error code reflects the general cause of the failure, allowing the application to handle this error condition appropriately. If the PATCH request fails, servers may also provide further details about the failure, such as XML or JSON formatted data containing specific error codes or diagnostic messages.

To capture this error information, you can utilize the httpPatchErrorData option. When this option is enabled, the behavior of PatchData changes; it does not return an error code for server error statuses. Instead, any error data provided in the server's response, regardless of its format, is copied into the result buffer provided by the caller. If this option is used, your application should check the value of the ResultCode property to obtain the HTTP status code returned by the server. This will enable you to determine if the operation was successful.

This method will cause the current thread to block until the operation completes, a timeout occurs or the post is canceled. During the operation, the OnProgress event will fire periodically, enabling the application to update any user interface objects such as a progress bar.

See Also

GetData Method, PostData Method, PutFile Method, OnProgress Event