局域网建设直播网站,郑州计算机培训机构哪个最好,我要自学网官网入口,昌黎县城乡建设局网站关于POST#xff0c;DELETE#xff0c;GET#xff0c;POST请求
get:是用来取得数据。其要传递过的信息是拼在url后面#xff0c;因为其功能使然#xff0c;有长度的限制
post:是用来上传数据。要上传的数据放在request的head里。没有长度限制。主要是用于增加操作
put:…关于POSTDELETEGETPOST请求
get:是用来取得数据。其要传递过的信息是拼在url后面因为其功能使然有长度的限制
post:是用来上传数据。要上传的数据放在request的head里。没有长度限制。主要是用于增加操作
put:也是用来上传数据。但是一般是用在具体的资源上。主要用于修改操作
delete:用来删除某一具体的资源上。
以下为每种请求方式的写法实例可用。
当然也可以将四种请求合并为一个通过的类调用实际运用过程中根据自己的实际需求调整
public function _curl_get($url, $dataarray(), $header array(), $timeout 30)
{
$url u r l . ? . h t t p b u i l d q u e r y ( url.?.http_build_query( url.?.httpbuildquery(data);
$ch curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 0); i n f o c u r l e x e c ( info curl_exec( infocurlexec(ch);
curl_close($ch);
return $info;
}
public function _curl_post($url, $dataarray(), $headerarray(), $timeout30)
{
$ch curl_init(); //初始化
curl_setopt($ch, CURLOPT_URL, $url); //设置链接
curl_setopt($ch, CURLOPT_POST, 1); //设置post方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //设置传输数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设置返回信息
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); i n f o c u r l e x e c ( info curl_exec( infocurlexec(ch); //接收返回信息
$errno curl_errno( $ch ); //返回错误代码
$post_info curl_getinfo( $ch ); //提交详情
curl_close($ch);
return $info;
}
public function _curl_put($url, $dataarray(), $headerarray(), $timeout30)
{
$ch curl_init(); //初始化
curl_setopt($ch, CURLOPT_URL, $url); //设置链接
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, “PUT”); //设置PUT方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //设置传输数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设置返回信息
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); i n f o c u r l e x e c ( info curl_exec( infocurlexec(ch); //接收返回信息
$errno curl_errno( $ch ); //返回错误代码
$post_info curl_getinfo( $ch ); //提交详情
curl_close($ch);
return $info;
}
public function _curl_delete($url, $dataarray(), $headerarray(), $timeout30)
{
$url u r l . ? . h t t p b u i l d q u e r y ( url.?.http_build_query( url.?.httpbuildquery(data);
$ch curl_init(); //初始化
curl_setopt($ch, CURLOPT_URL, $url); //设置链接
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “DELETE”); //设置DELETE方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //设置传输数据
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设置返回信息
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); i n f o c u r l e x e c ( info curl_exec( infocurlexec(ch); //接收返回信息
$errno curl_errno( $ch ); //返回错误代码
$post_info curl_getinfo( $ch ); //提交详情
curl_close($ch);
return $info;
}
#调用时根据数据类型可以自己定义header也可增加其它参数放入header数组
if($data_typejson)
{ d a t a j s o n e n c o d e ( datajson_encode( datajsonencode(data); h e a d e r a r r a y ( C o n t e n t − T y p e : a p p l i c a t i o n / j s o n , C o n t e n t − L e n g t h : . s t r l e n ( headerarray(Content-Type: application/json,Content-Length:.strlen( headerarray(Content−Type:application/json,Content−Length:.strlen(data),token:.$token);
}else
{ h e a d e r a r r a y ( t o k e n : . headerarray(token:. headerarray(token:.token);
}