File_get_contents cannot get the webpage content. filegetcontents_PHP tutorial

Source: Internet
Author: User
File_get_contents cannot get the webpage content, filegetcontents. File_get_contents cannot obtain the webpage content. during the verification process, the filegetcontents server often needs to obtain the information of a user from the channel server. There are two methods. file_get_contents cannot get the webpage content. filegetcontents

The server often needs to obtain the information of a user from the channel server during the authentication process. There are generally two methods: curl and file_get_contents.

In general, it will not be a problem if it is used like this.

 1 public function OauthPostExecuteNew($sign,$requestString,$request_serverUrl){ 2     $opt = array("http"=>array( 3         "method"=>"GET", 4         "header"=>array("param:".$requestString,"oauthsignature:".$sign), 5         "request_fulluri"=>true 6         ) 7     ); 8  9     $context = stream_context_create($opt);10     $res=file_get_contents($request_serverUrl, false, $context);11 12     return $res;13 }

However, because our server uses a proxy when connecting to the Internet, we need to bring the proxy parameter when using stream_context_create to access the channel server.

Therefore, add the "proxy" => $ proxy field to the $ opt array in the code above. After the file is added, it is found that the file_get_contents still does not work properly.

I was puzzled. I went to the official website to check file_get_contents and found that there was no proxy explanation. then I searched stream_context_create for this explanation.

params

Required$ Arr ['parameter '] = $ valueFormat. See the standard resource stream parameter list in context parameters.

Go to context_parameters to view the parameter configuration. Because we use the HTTP method, we can view the HTTP context

View proxy-related

proxyString

The address of the proxy server specified by URI. (E.g.Tcp: // proxy.example.com: 5100).

request_fulluriBoolean

When setTRUEThe entire URI will be used when building the request. (I. e.GET http://www.example.com/path/to/file.html HTTP/1.0). Although this is a non-standard request format, some proxy servers need it.

The default value isFALSE.

It is found that only the proxy is configured, and request_fulluri is not configured. then, the request_fulluri = true is added, and the verification is passed.

Note: When using the proxy parameter, you need to change http to tcp for specific reasons. Wait until I find it and update it here.

Http://www.bkjia.com/PHPjc/1097795.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1097795.htmlTechArticlefile_get_contents can not get the web content, filegetcontents server in the process of verification, often need to obtain a user information from the channel server. There are two methods ,...

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.