+ Start a Discussion
KrisztianKrisztian 

Https request with apex class

Please help me to wirite a class that can send a https request.

I create successful a https request based on: 
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_httprequest.htm

but I do not have any idea to create a https request.

Best Answer chosen by Krisztian
Vinita_SFDCVinita_SFDC
Hello,

Seems endpoint you provided isn't certified with an ssl certificate signed by some verified certificate authority (CA). Salesforce will therefore not accept the certificate and you get the exception you're seeing. You can either switch to unencrypted http or buy a proper certificate or try making your web service talk to SF with certificates which are issued by a CA trusted by SF.

This is of course only possible if you control the endpoint you're trying to talk to. Check out: http://wiki.developerforce.com/page/Making_Authenticated_Web_Service_Callouts_Using_Two-Way_SSL

Here's a pointer as to which CA's are accepted as valid authorities by SF: http://success.salesforce.com/ideaView?id=08730000000JziE

Hope it helps!

All Answers

Vinita_SFDCVinita_SFDC
Hello,

Please refer following help links and thread with sample code for this:

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000977iIAA

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

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

I am sorry, I made a typo :(

I create successful a http request based on:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_httprequest.htm

but I do not have any idea to create a https request.

Vinita_SFDCVinita_SFDC
Apologoies, in first sentence you said you have created "httep request" and the in last line you are saying "I do not have any idea to create a https request".

Do you mean "http response", as you have created http request?
KrisztianKrisztian
No, I want to send a https request. The web service accepts only https requests.

If I siply modify the endpoint to https://..... I catch an exception: 

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Vinita_SFDCVinita_SFDC
Hello,

Seems endpoint you provided isn't certified with an ssl certificate signed by some verified certificate authority (CA). Salesforce will therefore not accept the certificate and you get the exception you're seeing. You can either switch to unencrypted http or buy a proper certificate or try making your web service talk to SF with certificates which are issued by a CA trusted by SF.

This is of course only possible if you control the endpoint you're trying to talk to. Check out: http://wiki.developerforce.com/page/Making_Authenticated_Web_Service_Callouts_Using_Two-Way_SSL

Here's a pointer as to which CA's are accepted as valid authorities by SF: http://success.salesforce.com/ideaView?id=08730000000JziE

Hope it helps!
This was selected as the best answer
KrisztianKrisztian
Thanks for the answers!
The problem was in the ssl certificate.