Curl - allow equivalent in PHP CURL library

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

Reference Information. I have a circular DNS (one domain name is allowed for several IP addresses) and I want to send a request to a specific host. I am using virtual hosts based on the apache name and therefore the correct domain name should appear in the HTTP request.

I tried to specify the IP address 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 an SSL verification error (apparently CURL checks the certificate against the hostname URL and NOT Host: hostname).

Using the hosts not a convenient option.

+6
source share
3 answers

First, the best way to get an answer to how any curl option translates to libcurl (or PHP / CURL) is with --libcurl .

If you do this, you will find out that --resolve translates as CURLOPT_RESOLVE with libcurl, supported in PHP since version 5.5.0 . Supported by libcurl since 7.21.3 .

+10
source

I have a solution to this using Python.

In the .php file, just highlight the python output:

 <?php echo passthru("python python.py"); ?> 

In python.py:

 import httplib conn = httplib.HTTPSConnection('127.0.0.1'); url = "example.com" conn.request("GET", url) content = conn.getresponse() print content.read() conn.close() 
+1
source

if you are going to worry about branching another process, only the fork is twisted with the option "--resolve" compared to another script.

0
source

Source: https://habr.com/ru/post/914813/


All Articles