For security, our Web service hosts are often unable to access the Internet. Maintenance, but also through the springboard machine, SSH login to operate.
Sometimes our program needs to access the extranet. For example, you need to call an interface to other programs outside the network. What should I do now?
We can configure the host access via PHP's curlopt_httpheader of the curl function.
In development, I encountered an example of this.
There is an active program that needs to call an interface over Qzone.
The following code example:
$host = Array ("Host:act.qzone.qq.com"); $data = ' user=xxx&qq=xxx&id=xxx&post=xxx '; $url = ' http:// 192.168.1.12/xxx/xxx/api/'; Var_dump ($this->curl_post ($host, $data, $url));/* Submit Request * @param $host array required to configure the domain name array ("Host:act.qzone.qq.com"); * @param $data string required to submit the data ' user=xxx&qq=xxx&id=xxx&post=xxx ' .... * @param $ URL string to be submitted as ' http://192.168.1.12/xxx/xxx/api/'; */function Curl_post ($host, $data, $url) {$ch = Curl_init () ; $res = curl_setopt ($ch, Curlopt_url, $url); Var_dump ($res); curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE); curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_postfields, $data); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_httpheader, $host); $result = curl_exec ($ch); Curl_close ($ch); if ($result = = NULL) {return 0; } Tmdebugutils::d ebuglog ($result); return $result; }
Setting host via PHP CURL Curlopt_httpheader is a convenient solution to the problem of accessing the Extranet interface.
PHP Curl Host settings to access the specified host