本文介绍了curl --resolve等效于PHP CURL库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP CURL库中是否有等效的 curl --resolve ....

Is there an equivalent for curl --resolve .... in PHP CURL library ?

背景:我有轮叫DNS(一个域名解析为多个IP),我想向特定 主办。我使用基于名称的虚拟主机,因此正确的域名必须出现在HTTP请求中。

Background: I have round-robin DNS (one domain name resolves to multiple IPs), and I want to send a request to a specific host. I use apache name-based virtual hosts, and thus a correct domain name must appear in the HTTP request.

我已经尝试指定请求URL中的IP: curl_setopt($ ch,CURLOPT_HTTPHEADER,'Host:example.com') c $ c> curl_setopt($ ch,CURLOPT_URL,'127.0.0.1') code>。它适用于HTTP,但对于HTTPS,我得到SSL验证错误(显然CURL验证证书VS URL主机名和NOT 主机:主机名)。

I have tried specifying the IP in the request URL: curl_setopt($ch, CURLOPT_URL, '127.0.0.1'), and using curl_setopt($ch, CURLOPT_HTTPHEADER, 'Host: example.com'). It works for HTTP, but for HTTPS I get SSL verification error (apparently CURL verifies certificate vs. URL hostname and NOT Host: hostname).

使用 hosts 文件不是一个方便的选项。

Using hosts file is not a convenient option.

推荐答案

首先,获取任何 curl选项翻译为libcurl(或PHP / CURL)的答案的最佳方法是使用选项。

了解转换为 with libcurl,supported in PHP 。自之后,由libcurl支持。

If you do, you will learn that --resolve translates to CURLOPT_RESOLVE with libcurl, supported in PHP since 5.5.0. Supported by libcurl since 7.21.3.

这篇关于curl --resolve等效于PHP CURL库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:58