0
votes

When I am trying to access the salesforce API behind a proxy, I am not able to do so. When there is no proxy everything works fine.

Is there a way to set up the proxy details in the PHP code with the proxy id, username and password to allow the communication between our application and the salesforce API. I have found a few postings on the Java on how to do this but not in PHP..

1

1 Answers

2
votes

It depends on if you're using a SOAP or REST API, but both the PHP SoapClient and cURL libraries support proxies.

For SoapClient, the documentation states:

For HTTP authentication, the login and password options can be used to supply credentials. For making an HTTP connection through a proxy server, the options proxy_host, proxy_port, proxy_login and proxy_password are also available. For HTTPS client certificate authentication use local_cert and passphrase options. An authentication may be supplied in the authentication option. The authentication method may be either SOAP_AUTHENTICATION_BASIC (default) or SOAP_AUTHENTICATION_DIGEST.

For example, this is a simplified extract from some sample code connecting to Salesforce using SOAP:

$soapOptions = array();
$soapOptions['proxy_host']     = "localhost";
$soapOptions['proxy_port']     = (int) 8080; // Use an integer, not a string
$soapOptions['proxy_login']    = "username";
$soapOptions['proxy_password'] = "password";

$this->sforce = new SoapClient($wsdlPath, $soapOptions);

For cURL, take a look at the curl_setopt documentation, which has several options for proxies. Here is a simplified extract from some sample code connecting to Salesforce using REST:

$ch = curl_init();
...
curl_setopt($ch, CURLOPT_PROXY, "localhost");
curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "username:password");

$chResponse = curl_exec($ch);