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

Null Body For REST HTTP Callout Response

I'm trying to do an HTTP callout for this REST webservice; everything seems to be working except that I'm getting an empty body for the response when I know there should be something there.  If I paste the exact endpoint URL into my browser, I see xml returned.  What could possibly make see an empty response?


Code is below.  The webservice is MapAbc's reverse geocode service.  I've left off the last section of the URL which represents our org's key.



	Http h = new Http();
	HttpRequest req = new HttpRequest();
	string url = '';
	url = url + '&resType=xml';	//Response type
	url = url + '&enc=utf-8&spatialXml=<spatial_request method=\'searchPoint\'>';
	url = url + '<x>106.66423034667969</x>';	//Latitude
	url = url + '<y>26.61029052734375</y>';		//Longitude
	url = url + '<xs></xs><ys></ys>';
	url = url + '<poiNumber>0</poiNumber>';
	url = url + '<range>NaN</range><pattern>0</pattern><roadLevel>0</roadLevel><exkey></exkey></spatial_request>';
	url = url + '&a_k=***OurKey****';	//Key
	url = url + '&a_nocache=615704261174';
	HttpResponse res  = new HttpResponse(); 
	res = h.send(req);
	string resBody=res.getBody();
        system.debug('Response Body is: ' + resBody);   //Why is this null???	   


Debug logs:


08:34:49.056 (56000000)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
08:34:49.056 (56802000)|METHOD_ENTRY|[1]|01pK00000000Nrc|MapAbcTest.MapAbcTest()
08:34:49.056 (56859000)|SYSTEM_MODE_ENTER|false
08:34:49.056 (56909000)|SYSTEM_MODE_EXIT|false
08:34:49.056 (56942000)|METHOD_EXIT|[1]|MapAbcTest
08:34:49.056 (56988000)|CONSTRUCTOR_ENTRY|[1]|01pK00000000Nrc|<init>()
08:34:49.057 (57059000)|SYSTEM_MODE_ENTER|false
08:34:49.057 (57107000)|SYSTEM_MODE_EXIT|false
08:34:49.057 (57166000)|CONSTRUCTOR_EXIT|[1]|01pK00000000Nrc|<init>()
08:34:49.057 (57297000)|METHOD_ENTRY|[2]|01pK00000000Nrc|MapAbcTest.testing()
08:34:49.058 (58417000)|SYSTEM_MODE_ENTER|false
08:34:49.058 (58943000)|SYSTEM_METHOD_ENTRY|[26]|System.HttpRequest.setEndpoint(String)
08:34:49.059 (59003000)|SYSTEM_METHOD_EXIT|[26]|System.HttpRequest.setEndpoint(String)
08:34:49.059 (59081000)|SYSTEM_METHOD_ENTRY|[28]|System.HttpRequest.setMethod(String)
08:34:49.059 (59133000)|SYSTEM_METHOD_EXIT|[28]|System.HttpRequest.setMethod(String)
08:34:49.059 (59240000)|SYSTEM_METHOD_ENTRY|[30]|System.Http.send(APEX_OBJECT)
08:34:49.059 (59350000)|CALLOUT_REQUEST|[30]|System.HttpRequest[Endpoint=<spatial_request method='searchPoint'><x>106.66423034667969</x><y>26.61029052734375</y><xs></xs><ys></ys><poiNumber>0</poiNumber><range>NaN</range><pattern>0</pattern><roadLevel>0</roadLevel><exkey></exkey></spatial_request>&a_k=***OurKey***&a_nocache=615704261174, Method=GET]
08:34:49.287 (287725000)|CALLOUT_RESPONSE|[30]|System.HttpResponse[Status=OK, StatusCode=200]
08:34:49.287 (287820000)|SYSTEM_METHOD_EXIT|[30]|System.Http.send(APEX_OBJECT)
08:34:49.287 (287933000)|SYSTEM_METHOD_ENTRY|[31]|System.HttpResponse.getBody()
08:34:49.287 (287986000)|SYSTEM_METHOD_EXIT|[31]|System.HttpResponse.getBody()
08:34:49.288 (288079000)|SYSTEM_METHOD_ENTRY|[32]|System.debug(ANY)
08:34:49.288 (288154000)|USER_DEBUG|[32]|DEBUG|Response Body is: null
08:34:49.288 (288199000)|SYSTEM_METHOD_EXIT|[32]|System.debug(ANY)
08:34:49.288 (288275000)|SYSTEM_MODE_EXIT|false


And finally - this is what I get when I copy and paste that exact endpoint into a browser window:


<spatial_response type="SpatialBean" servername="mSIS03" versionname="1.0.9">
<SpatialBean ver="1.0">
<Province ver="1.0">
<City ver="1.0">
<District ver="1.0">
<roadList type="list">
<Road ver="1.0">
<ename>Guizun Expressway</ename>
<Road ver="1.0">
<ename>Service area</ename>
<Road ver="1.0">
<ename>Guizun Expressway Exit</ename>
<Road ver="1.0">
<ename>Guizun Expressway Entrance</ename>
<Road ver="1.0">
<ename>(unnamed road)</ename>
<poiList type="list"/>
<crossPoiList type="list">



vivek bvivek b

I m a newbie in HTTP callout please help me out
I m using the following code to get the result from the endpoint.

From the endpoint i m just sending 'test' as a response.
The result I m getting is System.HttpResponse[Status=null, StatusCode=0] .

public class callOut {
public static HttpRequest buildWebServiceRequest(){
// Build the XML Request
//construct an HTTP request

HttpRequest req = new HttpRequest();
//req.setHeader('content-type', 'text/xml; charset=utf-8');
// req.setHeader('Host','test');

return req;

public static HttpResponse invokeWebService(Http h, HttpRequest req){
//Invoke Web Service
HttpResponse res = h.send(req);
return res;

public static void handleWebServiceResponse(HttpResponse res){
//Parse and apply logic to the res message
System.debug('Status Code: ' + res.getStatusCode());
if (res.getStatusCode() == 200) {

System.debug('Callout body: ' + res.getBody());
} else {
System.debug('Callout failed: ' + res);

static testMethod void testWebService(){
//build the http request
HttpRequest req = buildWebServiceRequest();
//System.debug('After request: ' + req);
//write apex code to build a sample HttpResponse object
HttpResponse res = new HttpResponse();
//Apply test data and attributes to the HttpResponse object as needed

Did you ever get an answer to this question or fix it youself?  We're experiencing the same problem and are wondering how to get the content.  content-length reads 2215 bytes, but the responseBody is empty.
Jerry ClifftJerry Clifft
I beleive a GET does not have a body, a PUT would have a body.
The endpoint should be HTTPS not HTTP in case if you are trying to hit from salesforce apex.

check it by setting Content-Type in header?