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