SocketTools .NET Edition

HttpClient.PutData Method (String, Byte[], Int32, Byte[])

Send the contents of a byte array to the server and return the response.

[Visual Basic]
Overloads Public Function PutData( _
   ByVal resourceName As String, _
   ByVal buffer As Byte(), _
   ByVal length As Integer, _
   ByRef responseData As Byte() _
) As Boolean
[C#]
public bool PutData(
   string resourceName,
   byte[] buffer,
   int length,
   out byte[] responseData
);

Parameters

resourceName
A string that specifies the resource on the server that will receive the data being submitted. Depending on usage, this may be the name of a file or a URL which is used with an API.
buffer
A byte array which contains the data to be submitted.
length
An integer value which specifies the maximum number of bytes of data to sent. This value cannot be larger than the size of the buffer specified by the caller.
responseData
A byte array which will contain the response returned by the server. If you wish to include error responses, make sure you specify the HttpPutOptions.ErrorData option. Note that if the server returns a text response, it will typically be UTF-8 encoded.

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 PutData method transfers the data in a byte array and submits it to the server using the PUT command. This may be used to create a new file, replace the contents of an file which already exists, or a request to submit data to a service API.

If you are using this method to upload the contents of a file, check to make sure the service allows the use of the PUT command. Not all servers permit files to be created using this method, and some may require specific configuration changes be made to the server to support this functionality.

It may be required for the client authenticate itself by setting the UserName and Password properties prior to submitting the data.

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

See Also