1

The documentation tells us that XML, however un-hip, can be used as a request format.

The reality seems to be only HTTP 415 errors with UNSUPPORTED_MEDIA_TYPE.

Class:

@RestResource(urlMapping='/zrest/*')
global class ZREST {

    @HttpPost
    global static string doPost(string obj) {
      return 'OK: '+obj;
    }
}

Request:

POST https://cs8.salesforce.com/services/apexrest/zrest.xml HTTP/1.0
content-length: 37
accept: text/xml
content-type: text/xml
authorization: OAuth ***
user-agent: Whateva
host: cs8.salesforce.com
accept-encoding: gzip

<request>
  <obj>A</obj>
</request>

Response:

<?xml version="1.0" encoding="UTF-8"?>
<Errors>
    <Error>
        <errorCode>UNSUPPORTED_MEDIA_TYPE</errorCode>
        <message>Content-Type header specified in HTTP request is not supported: text/xml; charset=UTF-8</message>
    </Error>
</Errors>

Needless to say it works fine with application/json and {"obj" : "A"}!

  • Did you solve this? I think the 'OK: ' is the problem. Did you try with @HttpPost global static string doPost(string obj) { return obj; } – Acuariano Dec 27 '14 at 21:00
2

try: Accept: application/xml in your request header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.