function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ndrannapareddyndrannapareddy 

Send/Receive XML Response from Rest API

list<Account> accountsFromDev = new list<Account>();
String requestUrl = '/services/apexrest/v1/showAccount/';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(instance_Url+''+requestUrl);
req.setMethod('GET');

req.setHeader('Authorization', 'Bearer ' + accessToken);
HTTPResponse res = http.send(req);


Response: JSON format

[{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vi8dNAAR"},"Name":"Test2","Id":"001d000000Vi8dNAAR"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000001LSqwOAAT"},"Name":"Aethna Home Products","Id":"001d000001LSqwOAAT"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000001LT1W1AAL"},"Name":"WDop","Id":"001d000001LT1W1AAL"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000001LSqw8AAD"},"Name":"LeadCompany","Id":"001d000001LSqw8AAD"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7ipAAB"},"Name":"GenePoint","Id":"001d000000Vu7ipAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7iqAAB"},"Name":"United Oil & Gas, UK","Id":"001d000000Vu7iqAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7irAAB"},"Name":"United Oil & Gas, Singapore","Id":"001d000000Vu7irAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7isAAB"},"Name":"Edge Communications","Id":"001d000000Vu7isAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7itAAB"},"Name":"Burlington Textiles Corp of America","Id":"001d000000Vu7itAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7iuAAB"},"Name":"Pyramid Construction Inc.","Id":"001d000000Vu7iuAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7ivAAB"},"Name":"Dickenson plc","Id":"001d000000Vu7ivAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7iwAAB"},"Name":"Grand Hotels & Resorts Ltd","Id":"001d000000Vu7iwAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7ixAAB"},"Name":"Express Logistics and Transport","Id":"001d000000Vu7ixAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7iyAAB"},"Name":"University of Arizona","Id":"001d000000Vu7iyAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7izAAB"},"Name":"United Oil & Gas Corp.","Id":"001d000000Vu7izAAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000Vu7j0AAB"},"Name":"sForce","Id":"001d000000Vu7j0AAB"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000000VhjLYAAZ"},"Name":"Test Account","Id":"001d000000VhjLYAAZ"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001d000001EoDJwAAN"},"Name":"Revct","Id":"001d000001EoDJwAAN"}]





String output = res.getBody();



when i use this code to receive data from my Sandbox to Sandbox . i only get JSON response . 

How can i get the Response in XML format?






Pat PattersonPat Patterson
You can indicate that you want an XML response with the HTTP header:

req.setHeader('Accept', 'application/xml');