zoukankan      html  css  js  c++  java
  • php如何发起POST DELETE GET POST 请求

     

    get:是用来取得数据。其要传递过的信息是拼在url后面,因为其功能使然,有长度的限制

    post:是用来上传数据。要上传的数据放在request的head里。没有长度限制。主要是用于增加操作

    put:也是用来上传数据。但是一般是用在具体的资源上。主要用于修改操作

    delete:用来删除某一具体的资源上

    发起POST DELETE GET POST 请求通用类

        <?php   
        class commonFunction{  
            function callInterfaceCommon($URL,$type,$params,$headers){  
                $ch = curl_init();  
                $timeout = 5;  
                curl_setopt ($ch, CURLOPT_URL, $URL); //发贴地址  
                if($headers!=""){  
                    curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);  
                }else {  
                    curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-type: text/json'));  
                }  
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);  
                curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
                switch ($type){  
                    case "GET" : curl_setopt($ch, CURLOPT_HTTPGET, true);break;  
                    case "POST": curl_setopt($ch, CURLOPT_POST,true);   
                                 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;  
                    case "PUT" : curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT");   
                                 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;  
                    case "DELETE":curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");   
                                  curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break;  
                }  
                $file_contents = curl_exec($ch);//获得返回值  
                return $file_contents;  
                curl_close($ch);  
            }  
        }  
          
        ?>  
    $params="{user:"admin",pwd:"admin"}";  
    $headers=array('Content-type: text/json',"id: $ID","key:$Key");  
    $url=$GLOBALS["serviceUrl"]."/user";  
    $strResult= spClass("commonFunction")->callInterfaceCommon($url,"PUT",$params,$headers);

     

  • 相关阅读:
    分词器下载地址
    solr 查询方式
    solr 到 lucene
    Solr 安装与使用 Centos7
    线性表-串:KMP模式匹配算法
    金山——弱智的翻译程序
    FL2440移植Linux2.6.33.7内核
    FL2440移植u-boot2011.09
    【转】C/C++除法实现方式及负数取模详解
    循环缓冲类
  • 原文地址:https://www.cnblogs.com/agang-php/p/5210571.html
Copyright © 2011-2022 走看看