SocketTools .NET Edition

HttpClient.PostData Method (String, Byte[], Int32, Byte[], Int32, HttpPostOptions)

Submits the contents of the specified buffer to a resource on the server.

[Visual Basic]
Overloads Public Function PostData( _
   ByVal resourceName As String, _
   ByVal requestData As Byte(), _
   ByVal requestLength As Integer, _
   ByVal responseData As Byte(), _
   ByRef responseLength As Integer, _
   ByVal options As HttpPostOptions _
) As Boolean
[C#]
public bool PostData(
   string resourceName,
   byte[] requestData,
   int requestLength,
   byte[] responseData,
   ref int responseLength,
   HttpPostOptions options
);

Parameters

resourceName
A string that specifies the resource on the server that the data will be posted to. Typically this is the name of an executable script on the server. The resource name should be specified using an absolute path that begins with a leading slash character.
requestData
A byte array which contains the data to be submitted to the server.
requestLength
An integer value which specifies the size of the input buffer byte array. This value cannot be larger than the size of the buffer specified by the caller.
responseData
A byte array that will contain the output generated by the script. Typically this is HTML content which is generated by the script as a result of processing the data that was posted to it.
responseLength
An integer value which specifies the maximum number of bytes of data to store in the output buffer. This value cannot be larger than the size of the buffer specified by the caller
options
An HttpPostOptions enumeration that specifies one or more options when posting data to the server.

Return Value

This method returns a boolean value. If the method succeeds, the return value is true. If the method fails, the return value is false. To get extended error information, check the value of the LastError property.

Remarks

The PostData method submits the contents of the specified buffer to a script on the remote server and returns the result in a byte array provided by the caller. 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.

When encountering a server error during a request, the PostData method normally returns false, and no data is copied into the caller-provided buffer. The LastError property is updated to reflect the general cause of the failure, allowing the application to handle this error condition appropriately. Additionally, servers may 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 postErrorData option. When this option is enabled, the behavior of PostData changes; it does not return false for server error statuses. Instead, any error data provided in the server's response, regardless of its format, is copied into the buffer provided by the caller.

See Also

HttpClient Class | SocketTools Namespace | HttpClient.PostData Overload List