7

SF allowed the usage of Named Credentials with SOAP callouts but the documentation doesn't really go into details of how to pass/access the Username and Password to the stub.inputHttpHeaders_x . I have a webservice that uses basic authentication and I need to pass the details as below.

final String authHttpHeader = 'Basic ' + EncodingUtil.base64Encode( Blob.valueOf( User_Name + ':' + Password ) );
stub.inputHttpHeaders_x.put( 'Authorization', authHttpHeader );
stub.endpoint_x = 'callout:My_Named_Credential'

https://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_security_named_credential_web_service_callouts.htm

If some can give an example of how to access the username/password from the named credentials that will be a great help.

1 Answer 1

5

I haven't tested this, but when you are creating your Named Credential you have the option to tick "Generate Authorization Header", which should do this for you automatically:

enter image description here

3
  • I did check that box and wasn't able to get it to work , but i'll try again . Thanks @smukov
    – HSG
    Commented Oct 13, 2016 at 17:00
  • it doesn't work. I keep getting the error IO Exception: Unable to tunnel through proxy. Proxy returns "HTTP/1.0 404 Not Found"
    – HSG
    Commented Oct 14, 2016 at 18:29
  • 1
    That was a user error , sorry I had a bad character in the host name . Thanks @smukov
    – HSG
    Commented Oct 14, 2016 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .