The SetEncodingType method sets the type of encoding
used when optional parameter data is submitted with a request
for a resource. If you do not set the Content-Type request header
prior to submitting the request, the default content type provided to
the server will be determined by the encoding you choose. If you
specify HTTP_ENCODING_NONE, no default content type will be provided.
Because most services require a Content-Type header as part of a POST
request, this can cause the server to reject the request. The
SetContentType method can be used to explicitly specify
the content type for the request.
If the service you are connected with expects an XML formatted
request, it is recommended you use the PostXml method.
If the service expects JSON formatted text, use the PostJson
method. These methods ensure the correct encoding and content
type are always used. If the service expects some other kind of text
payload, you can set the appropriate content type using the
SetContentType method and then use the PostText
method to submit the request.
If you are using the PostData method to submit form
data to the server, in most cases you should use HTTP_ENCODING_URL.
If the form data contains XML text, you may need to use the
HTTP_ENCODING_XMLURL encoding type. However, in most cases, this is
not the appropriate encoding type for XML and should never be used
when submitting XML to a REST API endpoint.
If you are submitting a payload which contains binary data, you
would typically use HTTP_ENCODING_NONE and explicitly set the appropriate
content type using the SetContentType method. For example,
if you're submitting a JPEG image to a REST endpoint, you should not
use any encoding and set the Content-Type header to image/jpeg.
If your application needs to set the content type to a non-standard
value for a proprietary API, use the SetHeader
method to set the Content-Type header value. That method will not
perform any validation on the header value.