Filefile_get_contentsHTTPrequestfailed-PHP source code

Source: Internet
Author: User
Ec (2); * I have a question requesting the url from the php tutorial code. I need to call a service to use a query string from my php code. If I type a URL in my browser, it still works, but if I use the file to get the URL and the content () to make a call, I get: & nbsp; copy the code $ queryfile_get_contents (www.111cn.net), ec script ec (2), and script

/*
I have a question about the url of the php tutorial code. I need to call a service to use a query string from my php code. If I type a URL in my browser, it still works, but if I use the file to get the URL and the content () to call, I get:

The Code is as follows:
$ Query = file_get_contents ('HTTP: // www.111cn.net ');
Echo ($ query );

There are three possible problems

1. Is the allow_url_fopen option of php. ini open? If it is off, it cannot be accessed. Change it to on.
Ii. php. ini enabled the Security Mode
3. The machine is installed with strong fire prevention

Other solutions

*/

The Code is as follows:
$ Curl_handle = curl_init ();
Curl_setopt ($ curl_handle, curlopt_url, 'HTTP: // www.111cn.net ');
Curl_setopt ($ curl_handle, curlopt_connecttimeout, 2 );
Curl_setopt ($ curl_handle, curlopt_returntransfer, 1 );
Curl_setopt ($ curl_handle, curlopt_useragent, 'Your application name ');
$ Query = curl_exec ($ curl_handle );
Curl_close ($ curl_handle );

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.