php CURLOPT_RESOLVE 不起作用

标签 php curl

我在 Centos 6,PHP 5.6.35,

curl 7.59.0 (x86_64-redhat-linux-gnu) libcurl/7.59.0 OpenSSL/1.0.1e zlib/1.2.3 c-ares/1.14.0 libssh2/1.8.0 nghttp2/1.6.0

我正在尝试强制 curl 使用带 HTTPS 的 IP(我局域网中的网络服务器):

  curl_setopt($ch, CURLOPT_URL, "https://" . $domain . "/");
  curl_setopt($ch, CURLOPT_RESOLVE, array( $domain . ":443:192.168.1.10"));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_setopt($ch, CURLOPT_VERBOSE, true);
  $output = curl_exec($ch);

它一直连接到 $domain 的真实公共(public) IP。 我也明白了:

PHP Notice: Use of undefined constant CURLOPT_RESOLVE - assumed 'CURLOPT_RESOLVE' in ...

PHP Warning: curl_setopt() expects parameter 2 to be long, string given in ...

最佳答案

出于某种原因,来自 city-fan 的 curl 7.59 版本不起作用。

我已经在 Centos 7 上测试过

curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.21 Basic ECC zlib/1.2.7 libidn/1.28 libssh2/1.4.3

而且有效。

关于php CURLOPT_RESOLVE 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49908407/

相关文章:

php - 当我包含加密时,SQL 密码字段不起作用

linux - curl 表达式之间的区别

java - 连接到127.0.0.1端口8080失败: Connection refused

android - 如何在不使用 pushover 的情况下使用 http POST 向我的 Android 手机发送通知?

php - 使用 PHP 和证书作为身份验证连接到 FTPS

php - 验证文件上传服务器端 - 只允许使用 php 的图像

php - 需要 MySQL、PHP 帮助

php - 在 Facebook 应用程序中设置 SESSION 变量(或 cookie)

docker - Docker-连接到本地主机-连接被拒绝

php - 空接口(interface)相对于类属性有什么好处?