File_get_contents cannot get webpage content

Source: Internet
Author: User
: This article describes how file_get_contents cannot obtain webpage content. if you are interested in PHP tutorials, refer to it. 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.

 1publicfunction 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);1112return$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.

The preceding section introduces that file_get_contents cannot obtain the webpage content, including related content, and hopes to help friends who are interested in PHP tutorials.

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.