PHP obtains the network interface file stream

Source: Internet
Author: User
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 = "$size&time=$time"; GetWebFileStream($url);
POST call:
$strURL = "";$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!

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: 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.