SocketTools .NET Edition

HttpClient.PostText Method (String, String, String, Int32, HttpPostOptions)

Post text data to the server specifying one or more options and returns the response in a string.

[Visual Basic]
Overloads Public Function PostText( _
   ByVal resourceName As String, _
   ByVal textData As String, _
   ByRef responseData As String, _
   ByVal codePage As Integer, _
   ByVal options As HttpPostOptions _
) As Boolean
[C#]
public bool PostText(
   string resourceName,
   string textData,
   ref string responseData,
   int codePage,
   HttpPostOptions options
);

Parameters

resourceName
A string which specifies the path to a REST API endpoint or executable script on the server. The resource name should be specified using an absolute path which begins with a leading slash character.
textData
A string which contains the text that will be submitted to the server.
responseData
A string passed by reference that will contain the response from the server. Any newline characters included in the text will be normalized for the Windows platform.
codePage
An integer value which specifies the code page which should be used to convert the text to Unicode. If this value is zero, the active code page for the current locale will be used. An exception will be thrown if an invalid code page is specified.
options
A HttpPostOptions enumeration which 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 PostText method is used to submit text data to a REST endpoint or script which executes on the server. The server response is returned in a string passed by reference to the method. This method automatically sets the content type and encoding required for submitting plain text data to the server. If the text contains any Unicode characters, it will automatically be converted to UTF-8 prior to being submitted.

The content type specified with the request is normally text/plain, which is a generic type appropriate for most text. You can override this by setting the ContentType property prior to calling this method.

If the server rejects the request for any reason, this method will return false indicating the operation has failed. If you want the responseData string to include any error response from the server, specify HttpPostOptions.ErrorData as one of the options. In this case, the method will return true even if the server rejects the request and the responseData string will contain the error response. You can use the value of the ResultCode property to determine if the server accepted or rejected the request.

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 submitting large requests to the server.

See Also