具有Intranet应用程序的CURL请求

问题描述 投票:0回答:1

更新2:

print_r(curl_error($ch));

OpenSSL SSL_connect:与10.10.10.10:8339连接的SSL_ERROR_SYSCALL

我正在安装WAMP的公司网络上运行。我尝试使用Restlet Client连接到Internet API,并且能够发出GET请求而没有任何问题。

我尝试使用浏览器请求进行API调用,并且工作正常。

我无法在本地WAMP服务器中使用PHP CURL请求进行这些API调用。

我尝试使用CURL中启用的代理,但没有运气。我尝试启用ERROR_Reporting(E_ALL),但也看不到任何错误。

这是我的代码。

$url = "https://10.10.10.10:8339/beta/targets/1234234123/isolated/1567687263?samples=true";
$username="apiuser";
$password="apipassword";
//$proxy = 'proxy:8080';
//$proxyauth = 'proxyuser:proxypassword';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
print_r($output);
//print_r($info);
curl_close($ch);

以上输出为空白

enter image description here

php rest api curl wamp
1个回答
1
投票

您遇到的问题是,您在不指定主机名的情况下连接到HTTPS服务器。因此,无法验证属于HTTPS的主机名。

最好的办法是使用主机名。而且,如果您使用的是自签名证书,请将其安装在服务器上,以便对其进行验证。

代替,您可以在cURL中禁用此检查:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

另请参见:https://stackoverflow.com/a/15237205/362536

© www.soinside.com 2019 - 2024. All rights reserved.