+ Start a Discussion
logontokartiklogontokartik 

Httprequest Callout Class not working as expected

Hello,

I wrote a Http class to test the callout to the REST WS written .NET. I tried to run in different ways but I am not able to get the proper response back. Now I am getting a Media type error. Can anyone pls help if they had the similar issue in the past. 

Below is my Http Class.

 

public String getLocationStatus() { 
   String result = ' ';
   HttpRequest httpreq = new HttpRequest();
   httpreq.setMethod('GET');
   httpreq.setHeader('Content-Type', 'application/atom+xml;charset=utf-8'); 
   
   httpreq.setEndpoint('XXXXXXXXXX');
   
 
   Http http = new Http();
      HTTPResponse response = http.send(httpreq);
      result = response.getBody(); 
      system.debug(response.getBody());
      return result;
     }
The error I am getting is 
08:18:27.044|CALLOUT_REQUEST|[71]|System.HttpRequest[Endpoint=XXXXXXXX, Method=GET] 08:18:27.439|CALLOUT_RESPONSE|[71]|System.HttpResponse[Status=Bad Request, StatusCode=400] 08:18:27.439|METHOD_EXIT|[71]|System.Http.send(APEX_OBJECT) 08:18:27.439|METHOD_ENTRY|[72]|System.HttpResponse.getBody() 08:18:27.439|METHOD_EXIT|[72]|System.HttpResponse.getBody() 08:18:27.439|METHOD_ENTRY|[73]|System.debug(ANY) 08:18:27.439|METHOD_ENTRY|[73]|System.HttpResponse.getBody() 08:18:27.439|METHOD_EXIT|[73]|System.HttpResponse.getBody() 08:18:27.439|USER_DEBUG|[73]|DEBUG|<?xml version="1.0" encoding="utf-8" standalone="yes"?> <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code></code> <message xml:lang="en-US">Media type requires a '/' character.</message> </error>
Not sure what that means, I tried using all content types.
Please help.

 

Best Answer chosen by Admin (Salesforce Developers) 
logontokartiklogontokartik

I have got it working. 

 

We need to set the ACCEPT Header explicitly in SFDC - 

 

 

  req.setHeader('Accept', 'application/atom+xml;charset=utf-8');
Not sure what Standard Salesforce Accept Header looks like though.. 

 

All Answers

Ritesh AswaneyRitesh Aswaney

Hey, you may have already, but quickly checking if you've tried

 

conn.setRequestProperty("Content-type","text/xml");

conn.setRequestProperty("Content-type","application/xml");

Ritesh AswaneyRitesh Aswaney

"This was not a known issue previously, but it is now being tracked to be fixed in a future release. Media types with quoted parameter values are not being parsed correctly, causing the error message you saw originally. Removing that value from the accept header, or using a different client application, should get you around this issue."

 

from 

 

http://social.msdn.microsoft.com/Forums/en/adodotnetdataservices/thread/e47ec51b-ea38-49f7-9814-d113907d4e3a

 

logontokartiklogontokartik

I have got it working. 

 

We need to set the ACCEPT Header explicitly in SFDC - 

 

 

  req.setHeader('Accept', 'application/atom+xml;charset=utf-8');
Not sure what Standard Salesforce Accept Header looks like though.. 

 

This was selected as the best answer