使用代理背后的 PHP 工具包访问 salesforce API

发布于 2024-12-05 06:01:08 字数 173 浏览 1 评论 0原文

当我尝试访问代理后面的 salesforce API 时,我无法这样做。当没有代理时一切正常。

有没有办法在 PHP 代码中使用代理 ID、用户名和密码设置代理详细信息,以允许我们的应用程序和 salesforce API 之间进行通信。我在 Java 上找到了一些关于如何执行此操作的帖子,但在 PHP 中却没有。

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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠魁 2024-12-12 06:01:08

这取决于您使用的是 SOAP 还是 REST API,但 PHP SoapClient 和 cURL 库支持代理。

对于 SoapClient,文档指出:

对于 HTTP 身份验证,登录名和密码选项可用于
提供凭证。用于通过代理建立 HTTP 连接
服务器,选项 proxy_host、proxy_port、proxy_login 和
proxy_password 也可用。对于 HTTPS 客户端证书
身份验证使用 local_cert 和密码选项。一个
身份验证可以在身份验证选项中提供。这
身份验证方法可以是 SOAP_AUTHENTICATION_BASIC
(默认)或 SOAP_AUTHENTICATION_DIGEST。

例如,这是一些 示例的简化摘录使用 SOAP 连接到 Salesforce 的代码

$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);

对于 cURL,请查看 curl_setopt 文档,其中有多个代理选项。以下是一些连接到的示例代码的简化摘录使用 REST 的 Salesforce:

$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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文