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
pidruspidrus 

How to make a REST callout from Apex over HTTPS

Hi,

 

I've been struggling with this for almost a week and can use some help from the community...

 

 

I'm making a call from SalesForce to a JSP on an external web-server (in our control) using the following code:

 

 

 

HttpRequest req = new HttpRequest(); //Set HTTPRequest params req.setMethod('POST'); req.setEndpoint('https://somehost/somefile.jsp'); // set the client certificate.

  String s_certificate = 'certificate goes here';

req.setClientCertificate(s_certificate,'password'); //Set the HTTPRequest body

String body = 'the body of the message'; req.setBody(body); Http http = new Http(); try { //Execute web service call here HTTPResponse res = http.send(req); //Helpful debug messages System.debug(res.toString()); System.debug('STATUS:'+res.getStatus()); System.debug('STATUS_CODE:'+res.getStatusCode()); } catch(System.CalloutException e) { System.debug('Got exception: ' + e); }

 

When I execute this code (either with or without @future), I get the following exception:

 

System.CalloutException: DER input, Integer tag error

 

I believe there is something wrong with either the certifate I'm using for req.setClientCertificate(), the certificate on the server, or the server configuration, but I'm sure what is going on exactly.

 

If somebody has experience making an Apex call over HTTPS, please reply with some overview on how it works, what the setup needs to be, what kind of certificates are needed, how the web-server needs to be configured (e.g. require client authentication?) and if there is anything wrong with the code.

 

This is becoming an urgent matter so please help!!

 

Thanks, 

 

IM.

 

 

 

SuperfellSuperfell
The format of your certificate string is wrong, i don't have the details to hand, but there is a thread somewhere on the forum that covers this in detail.