: 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
proxy
String
The address of the proxy server specified by URI. (E.g.Tcp: // proxy.example.com: 5100).
request_fulluri
Boolean
When setTRUE
The 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.