CURL cannot obtain the content of other local Virtual Hosts

Source: Internet
Author: User
Windows764bit, nginx1.5.8, php5.4.22, two virtual hosts, a.cn, B .cn {code...} on the virtual host B .cn, get the content of a file under a.cn through curl. The result page returns 504GatewayTime-out. There is a post on stackoverflow. I follow this post to do... windows 7 64bit, nginx 1.5.8, php 5.4.22, 2 virtual hosts, a.cn, B .cn

hosts:127.0.0.1   a.cn127.0.0.1   b.cn

On the VM B .cn, use curl to obtain the content of a file under a.cn.
Result page return504 Gateway Time-out.

There is a post on stackoverflow. I followed it, but it is still unsolved.
Http://stackoverflow.com/questions/9276114/php-curl-doesnt-see-the-etc-hosts

This is another post, but I have not solved the problem.
Http://stackoverflow.com/questions/3390549/set-curl-to-use-local-virtual-hosts

How can this problem be solved?

Previous Code (run in php on the command line. php test. php and test. php can return the following results)

    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, 'http://a.cn' . '/u/ne.php');    curl_setopt($ch, CURLOPT_HEADER, false);    curl_setopt($ch, CURLINFO_HEADER_OUT, true);    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    curl_setopt($ch, CURLOPT_AUTOREFERER, true);    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);    $data = curl_exec($ch);    curl_close($ch);    echo $data;

Code changed according to stackoverflow

    $header = array(        "Host: a.cn",        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",        "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3",        "Accept-Encoding: gzip,deflate,sdch",        "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4",        "Cache-Control: max-age=0",        "Connection: keep-alive",    );    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1' . '/u/ne.php');    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);    curl_setopt($ch, CURLOPT_HEADER, false);    curl_setopt($ch, CURLINFO_HEADER_OUT, true);    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    curl_setopt($ch, CURLOPT_AUTOREFERER, true);    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);    $data = curl_exec($ch);    curl_close($ch);    echo $data;

Reply content:

Windows 7 64bit, nginx 1.5.8, php 5.4.22, 2 virtual hosts, a.cn, B .cn

hosts:127.0.0.1   a.cn127.0.0.1   b.cn

On the VM B .cn, use curl to obtain the content of a file under a.cn.
Result page return504 Gateway Time-out.

There is a post on stackoverflow. I followed it, but it is still unsolved.
Http://stackoverflow.com/questions/9276114/php-curl-doesnt-see-the-etc-hosts

This is another post, but I have not solved the problem.
Http://stackoverflow.com/questions/3390549/set-curl-to-use-local-virtual-hosts

How can this problem be solved?

Previous Code (run in php on the command line. php test. php and test. php can return the following results)

    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, 'http://a.cn' . '/u/ne.php');    curl_setopt($ch, CURLOPT_HEADER, false);    curl_setopt($ch, CURLINFO_HEADER_OUT, true);    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    curl_setopt($ch, CURLOPT_AUTOREFERER, true);    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);    $data = curl_exec($ch);    curl_close($ch);    echo $data;

Code changed according to stackoverflow

    $header = array(        "Host: a.cn",        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",        "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3",        "Accept-Encoding: gzip,deflate,sdch",        "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4",        "Cache-Control: max-age=0",        "Connection: keep-alive",    );    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1' . '/u/ne.php');    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);    curl_setopt($ch, CURLOPT_HEADER, false);    curl_setopt($ch, CURLINFO_HEADER_OUT, true);    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    curl_setopt($ch, CURLOPT_AUTOREFERER, true);    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);    $data = curl_exec($ch);    curl_close($ch);    echo $data;

The code is correct after testing.
504 errors may occur on the web server. Use curl_error () to view the specific information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.