PHP Gets the network interface file stream

Source: Internet
Author: User

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); &nbsp ;      //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

Related Article

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.