Get the file stream inside the network interface
PHP Development calls a variety of interfaces is unavoidable, sometimes need to pass a very many parameters.
' & ' is sometimes parsed as ' & ' during the pass-through parameters Cause the request to fail
After looking for data and comparison, found PHP provides a variety of methods: curl, fopen, file_get_contents, etc., on the operability, reliability and efficiency cUrl is good.
The proportion of the participation is as follows:
/** * get the file stream inside the network interface **/ Public Function Getwebfilestream ($strUr L, $urlParams = ', $type = ' get ') { $stream = ""; if (!isset ($STRURL) | | Empty ($STRURL)) return ""; //Initialize & nbsp $ch = Curl_init (); if ($type = = = ' Post ') { CURL_SETOPT_A Rray ($ch,[ Curlopt_url &N Bsp;=> $strUrl, Curlopt_returntransfer => 1, &nbs P curlopt_post 1, &NB Sp Curlopt_header 0, & nbsp &nbSp curlopt_postfields => $urlParams ]); & nbsp } else{ Curl_setopt_array ($ch,[ &N Bsp Curlopt_url => $STRURL, Curlopt_returntransfer => 1, Curlopt_header = 0 ]) ; } //output $stream = curl_exec ($ch);   ; //Infer If curl Request timed out if (Curl_errno ($ch)) { &NBS P $stream = file_get_contents ($STRURL); } //close &NB SpCurl_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= $md 5_key"; $strJSON = Getwebfilestream ($strURL, $urlParams, ' post ');
The above cases are for reference only, many other curl knowledge points please refer to the PHP manual!
PHP Gets the network interface file stream