Encapsulates the Curl class, the post get method implements the Web request

Source: Internet
Author: User

<?php
Class Ramdemo
{
Get method
function Ramget ($url, $arr)
{
if ($arr! = ") {
$ar =array ();
foreach ($arr as $k = = $v) {
$ar []= $k. ' = '. $v;
}
$url = $url. '? '. Implode (' & ', $ar);
}
return $url;d ie;
return $this->curl ($url, $arr, ' GET ', false,false);
}
Post method
function Rampost ($url, $arr)
{
return $this->curl ($url, $arr, ' POST ', false,false);
}
Curl method
Function Curl ($url, $data, $method, $setcooke =false, $cookie _file=false) {
$ch = Curl_init (); 1. Initialization
curl_setopt ($ch, Curlopt_url, $url); 2. Request Address
curl_setopt ($ch, Curlopt_customrequest, $method)//3. Request method
4. The parameters are as follows
curl_setopt ($ch, Curlopt_ssl_verifypeer,false);
curl_setopt ($ch, Curlopt_ssl_verifyhost,false);
curl_setopt ($ch, Curlopt_useragent, ' mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) gecko/20100101 firefox/44.0 '); Specify request mode (browser)
curl_setopt ($ch, curlopt_followlocation,1);
curl_setopt ($ch, curlopt_autoreferer,1);
if ($method = = "POST") {//5.post method when adding data
curl_setopt ($ch, Curlopt_postfields, $data);
}
if ($setcooke ==true) {
Save the generated cookie in the specified file
curl_setopt ($ch, Curlopt_cookiejar, $cookie _file);
}else{
Read cookie information directly from the file
curl_setopt ($ch, Curlopt_cookiefile, $cookie _file);
}
curl_setopt ($ch, curlopt_returntransfer,1);
$output = curl_exec ($ch);

if (Curl_errno ($ch)) {
Return Curl_error ($ch);
}
Curl_close ($ch);
return $output;
}
}
?>

Encapsulates the Curl class, the post get method implements the Web request

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.