Encoding Property  
 

Gets and sets the content encoding type.

Syntax

object.Encoding = [type ]

Remarks

The Encoding property explicitly sets the type of encoding used when optional parameter data is submitted with a request for a resource. The following encoding types are supported:

Value Description
httpEncodingNone No encoding will be applied to the content of a request and no default content type will be specified.
httpEncodingUrl Non-printable and extended ASCII characters will be encoded so they can be safely used with URLs and form data. Encoded characters will be represented by a percent symbol prefix, followed by a two digit hexadecimal value which represents the ASCII character code. This encoding is typically used with web services which process HTML form data. If the content type has not been explicitly specified, it will default to application/x-www-form-urlencoded.
httpEncodingXml This encoding specifies the content being submitted to the server contains XML structured data. If the content type has not been defined, it will default to application/xml, which is the official MIME media type for XML text. Legacy services may expect text/xml as the content type.
httpEncodingJson This encoding specifies the content being submitted to the server contains JSON structured data. If the content type has not been defined, it will default to application/json, which is the official MIME media type for JSON text. In rare cases, legacy services may expect text/x-json as the content type.
httpEncodingUtf8 This encoding specifies the content is unstructured text which has been UTF-8 encoded. If the content type has not been defined, it will default to text/plain; charset=utf-8 which is appropriate for any kind of general text payloads. If you use the Unicode version of the functions in this library, all text is normally submitted as UTF-8 encoded text.
httpEncodingAnsi This encoding specifies the content is unstructured text and may not be UTF-8 encoded if the ANSI version of the functions in this library are used. This encoding is not recommended unless there is a specific need to send text using a specific character set. If the content type has not been defined, it will default to plain/text.
httpEncodingXmlUrl This encoding is identical to URL encoding, except spaces are not encoded. It is used with legacy web services which expect form data in an XML format and cannot process encoded whitespace. This encoding should not be specified for services which use REST APIs. If the content type has not been specified, it will default to application/x-www-form-urlencoded.

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 property. If you specify httpEncodingNone, 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 ContentType property 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 m,ethods 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 by setting the ContentType property 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 httpEncodingUrl. If the form data contains XML text, you may need to use the httpEncodingXmlUrl 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 httpEncodingNone and explicitly set the appropriate content type using the ContentType property. 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.

Data Type

Integer (Int32)

See Also

ContentType Property, PostData Method, PostJson Method, PostXml Method, SetHeader Method