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 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.
The method may be used in one of two ways, depending on the
needs of the application. The first approach is to pre-allocate a
buffer large enough to store the resulting output of the script. In
this case, the lpvResult parameter will point to the buffer
that was allocated by the client and the value that the
lpcbResult parameter points to should be initialized to the
size of that buffer.
The second approach is to have the lpvResult
parameter point to a global memory handle which will contain the data
when the method returns. In this case, the value that the
lpcbResult parameter points to must be initialized to zero. It
is important to note that the memory handle returned by the method
must be freed by the application, otherwise a memory leak will occur.
See the example code below.
It is important for your application to initialize the value of the
lpcbResult parameter correctly. This parameter must be passed
by reference and if it is not initialized properly it can cause
unexpected behavior or corrupt the process heap. If an error occurs
when issuing the PATCH request to the server, the variable passed to
this method may have a value of zero when the method returns,
indicating no data has been returned to the caller.
When encountering a server error during a request, the
PatchData method normally returns HTTP_ERROR, and no data is
copied into the caller-provided buffer. The last error code for the
current thread is updated to reflect 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
HTTP_PATCH_ERRORDATA option. When this option is enabled, the
behavior of PatchData changes; it does not return HTTP_ERROR
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 call GetResultCode 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
post completes, a timeout occurs or the operation is canceled. During
the transfer, the HTTP_EVENT_PROGRESS event will be periodically
fired, enabling the application to update any user interface
controls. Event notification must be enabled, either by calling
EnableEvents, or by registering a callback function using
the RegisterEvent method.
To determine the current status of the transaction while it is in
progress, use the GetTransferStatus method.