PHP obtains the network interface file stream to obtain the file stream in the network interface
Php developers call various interfaces, and sometimes many parameters need to be passed.
During parameter transfer, '&' is sometimes parsed as '&', causing request failure.
After searching for information and comparison, we found that php provides multiple methods: cUrl, fopen, file_get_contents, etc. cURL is good in terms of operability, reliability, and efficiency.
The reference cases are as follows:
/*** Get the file stream in the network interface **/public function GetWebFileStream ($ strUrl, $ urlParams = '', $ type = 'get ') {$ stream = ""; if (! Isset ($ strUrl) | empty ($ strUrl) return ""; // initialize $ ch = curl_init (); if ($ type = 'post ') {curl_setopt_array ($ ch, [CURLOPT_URL => $ strUrl, scheme => 1, CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_POSTFIELDS => $ urlParams]);} else {curl_setopt_array ($ ch, [CURLOPT_URL => $ strUrl, CURLOPT_RETURNTRANSFER => 1, CURLOPT_HEADER => 0]);} // output result $ stream = curl_exec ($ ch ); // Determine whether the curl request times out if (curl_errno ($ ch) {$ stream = file_get_contents ($ strUrl) ;}// close curl_close ($ ch); return $ stream ;}
GET Call:
$url = "http://zhibo.fx678.com/index.php?page=htnews&ps=$size&time=$time"; GetWebFileStream($url);
POST call:
$strURL = "http://reschart.fx678.com/fx678dataWebService/UpdateDataContext.asmx/GetWillAndPublishedDateS";$urlParams ="willtop=$willSize&top=$size&Clientdate=$clientDate&Key=$md5_key";$strJSON = GetWebFileStream($strURL,$urlParams,'post');
The above cases are for reference only. For more information about cUrl, see The php Manual!