• vivek b
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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 force.com 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 = 'http://search1.mapabc.com/sisserver?highLight=false&config=SPAS&ver=2.0';
	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';
	
	req.setEndpoint(url);
    	req.setMethod('GET');    
	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=http://search1.mapabc.com/sisserver?highLight=false&config=SPAS&ver=2.0&resType=xml&enc=utf-8&spatialXml=<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">
<name>贵州省</name>
<code>520000</code>
</Province>
<City ver="1.0">
<name>贵阳市</name>
<code>520100</code>
<telnum>0851</telnum>
</City>
<District ver="1.0">
<name/>
<code/>
<x/>
<y/>
<bounds/>
</District>
<roadList type="list">
<Road ver="1.0">
<id>08511789</id>
<name>贵遵高速</name>
<direction>EastNorth</direction>
<distance>38.340862</distance>
<width>12</width>
<ename>Guizun Expressway</ename>
<level>41000</level>
</Road>
<Road ver="1.0">
<id>0851804</id>
<name>服务区</name>
<direction>EastNorth</direction>
<distance>73.932838</distance>
<width>4</width>
<ename>Service area</ename>
<level>43000</level>
</Road>
<Road ver="1.0">
<id>08512255</id>
<name>贵遵高速出口</name>
<direction>WestSouth</direction>
<distance>339.452545</distance>
<width>8</width>
<ename>Guizun Expressway Exit</ename>
<level>44000</level>
</Road>
<Road ver="1.0">
<id>08512254</id>
<name>贵遵高速入口</name>
<direction>WestSouth</direction>
<distance>339.452545</distance>
<width>8</width>
<ename>Guizun Expressway Entrance</ename>
<level>44000</level>
</Road>
<Road ver="1.0">
<id>08511942</id>
<name>兴筑东路</name>
<direction>WestSouth</direction>
<distance>364.536499</distance>
<width>20</width>
<ename>(unnamed road)</ename>
<level>44000</level>
</Road>
</roadList>
<poiList type="list"/>
<crossPoiList type="list">
<cross>
<name>贵遵高速-服务区</name>
<x>106.663529</x>
<y>26.599138</y>
</cross>
</crossPoiList>
</SpatialBean>
</spatial_response>

 

 

  • September 08, 2011
  • Like
  • 0