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
Gaurish Gopal GoelGaurish Gopal Goel 

Authentication Failed in HTTP Callout

I am making an HTTP Callout using Apex in which I am not getting authenticated.

 

There are two required parameters : username and api_key

 

Http h = new Http();

HttpRequest req = new HttpRequest();

req.setEndpoint('whatever the url is');

req.setmethod(POST);

 

req.setheader('username','goelgaurish@gmail.com');

req.setheader('api_key','idsfiubsdkjrnwopeiurwoheoir12431);

 

HttpResponse res = h.send(req);
return res.getBody();

 

I am not able to get a success while authenticating. Please correct the code if I am missing something.

 

Ashish_SFDCAshish_SFDC

Hi Gaurish, 

 

Try adding the future annotation. 

 

  @future (callout=true)
  public static void doCalloutFromFuture()

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm

 

 

Ashish_SFDCAshish_SFDC

Also, see the samples below, 

 

http://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts

 

 

Regards,

Ashish