PHP initiates post DELETE GET POST request

Source: Internet
Author: User

Original link: http://blog.csdn.net/lengxue789/article/details/8254667

About Post,delete,get,post Requests

Get: is used to get data. The information that is to be passed is spelled behind the URL, because of its function, with the limitation of length

Post: is used to upload data. The data to be uploaded is placed in the head of request. There is no length limit. Mainly used to increase the operation

Put: Also used to upload data. But it is generally used in specific resources. Primarily for modifying operations

Delete: Used to delete a specific resource.

Initiating post DELETE GET POST request General class

1<?PHP2 classcommonfunction{3     functionCallinterfacecommon ($URL,$type,$params,$headers){4         $ch=curl_init ();5         $timeout= 5;6curl_setopt ($ch, Curlopt_url,$URL);//Destination Address7 //Request Header8         if($headers!=""){9curl_setopt ($ch, Curlopt_httpheader,$headers);Ten}Else { Onecurl_setopt ($ch, Curlopt_httpheader,Array(' Content-type:text/json ')); A         } -curl_setopt ($ch, Curlopt_returntransfer, 1);//returns the result, not output -curl_setopt ($ch, Curlopt_connecttimeout,$timeout);//Timeout period the //Request type -         Switch($type){ -              Case"GET": -curl_setopt ($ch, Curlopt_httpget,true); +              Break; -              Case"POST": +curl_setopt ($ch, Curlopt_post,true);  Acurl_setopt ($ch, Curlopt_postfields,$params); at              Break; -              Case"PUT": -curl_setopt ($ch, Curlopt_customrequest, "PUT");  -curl_setopt ($ch, Curlopt_postfields,$params); -              Break; -              Case"DELETE": incurl_setopt ($ch, Curlopt_customrequest, "DELETE");  -curl_setopt ($ch, Curlopt_postfields,$params); to              Break; +         } -         $file _contents= Curl_exec ($ch);//Get return value theCurl_close ($ch); *         return $file _contents; $     }Panax Notoginseng } -?>

Call

1<?PHP2 $params= "{user:\" admin\ ", Pwd:\" admin\ "}";3 $headers=Array(' Content-type:text/json ', "ID:$ID"," Key:$Key");4 $url=$GLOBALS["serviceurl"]. " /user ";5 $strResult= Spclass ("commonfunction")->callinterfacecommon ($url, "PUT",$params,$headers);6?>

$headers: If the parameter value needs to be passed in the header, you can pass it in an array format

PHP initiates post DELETE GET POST 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.