Php-to-url-action classes: URL stitching, get fetch page, post fetch page (with pass Parameter)

Source: Internet
Author: User

/** @brief URL wrapper class to encapsulate common URL request operations **/classurl{Private $error;  public function__construct () {$this->error =NewErrorcase (); }    /** * combineurl * Stitching URL * @param string $baseURL based URL * @param array $keysArr List of parameters * @retu RN string returns the URL of the stitching*/     public functionCombineurl ($baseURL,$KEYSARR){        $combined=$baseURL."?"; $VALUEARR=Array(); foreach($KEYSARR  as $key=$val){            $VALUEARR[] = "$key=$val"; }        $keyStr=implode("&",$VALUEARR); $combined.= ($keyStr); return $combined; }    /** * get_contents * server obtains content via GET request * @param string $url requested url, post-stitched * @return String request What's returned*/     public functionGet_contents ($url){        if(Ini_get("allow_url_fopen") = = "1") {            $response=file_get_contents($url); }Else{            $ch=Curl_init (); curl_setopt ($ch, curlopt_ssl_verifypeer,FALSE); curl_setopt ($ch, curlopt_returntransfer,TRUE); curl_setopt ($ch, curlopt_url,$url); $response= Curl_exec ($ch); Curl_close ($ch); }        //-------request is empty        if(Empty($response)){            $this->error->showerror ("50001"); }        return $response; }    /** Get * Get method Request resource * @param string $url based on BaseURL * @param array $keysArr List of parameters * @r Eturn string returns the contents of the resource*/     public functionGet$url,$KEYSARR){        $combined=$this->combineurl ($url,$KEYSARR); return $this->get_contents ($combined); }    /** * Post * POST method Request resource * @param string $url based on BaseURL * @param array $KEYSARR The requested parameter list * @ param int $flag Flag bit * @return The contents of the resource returned by string*/     public functionPost$url,$KEYSARR,$flag= 0){        $ch=Curl_init (); if(!$flag) curl_setopt ($ch, curlopt_ssl_verifypeer,FALSE); curl_setopt ($ch, curlopt_returntransfer,TRUE); curl_setopt ($ch, curlopt_post,TRUE); curl_setopt ($ch, curlopt_postfields,$KEYSARR); curl_setopt ($ch, curlopt_url,$url); $ret= Curl_exec ($ch); Curl_close ($ch); return $ret; }}

Php-to-url-action classes: URL stitching, get fetch page, post fetch page (with pass Parameter)

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.