首頁  >  文章  >  後端開發  >  发送POST请求在request中有以次data内容

发送POST请求在request中有以次data内容

WBOY
WBOY原創
2016-06-13 11:57:221082瀏覽

发送POST请求在request中有以下data内容
接口实例:
http://199.199.99.199:8080/cloudTVPlatform/external/api?act=notifyNewDeveloper&PID=CloudTVDN&pversion=1.0&format=JSON
请求方式:POST
请求URL参数说明: 
act:操作类型,notifyNewDeveloper,必须
pversion:协议版本,默认为1.0 
PID:合作伙伴代码PID,填写CloudTVDN,必须
format:返回的数据格式,支持XML和JSON,默认为JSON
通知数据(POST DATA)实例
POST请求在request中获取参数data内容如下
{
    " developerCount ": 2,
    "data": [
        {
            "originalID": "123",
            "developerName": "liux",
            "developerType": "个人",
            "trueName": "刘",
            "eMail": "[email protected]",
            "phone": "86-10-62565615-208",
            "mobile": "86-13900000000",
            "fax": "86-10-62565615-208",
            "ECURL": "http://DNS/123.JPG",
            "CRURL": "",
            "CTURL": "",
            "registerTime": "2014-04-02 14:14:19"
        },
        {
            "originalID": "124",
            "developerName": "liux1",
            "developerType": "公司",
            "trueName": "百度",
            "eMail": "[email protected]",
            "phone": "86-10-62565615-208",
            "mobile": "86-13900000000",
            "fax": "86-10-62565615-208",
            "ECURL": "http://DNS/124.JPG",
            "CRURL": " http://DNS/125.JPG ",
            "CTURL": " http://DNS/126.JPG ",
            "registerTime ": "2014-04-02 14:14:19"
        }
    ]
}

返回数据:
返回数据格式:JSON
返回实例:
{
    "resultCode": "Success",
    "resultMessage": "成功处理"
}
那是客户端提供的接口,而我在服务器端我调用这接口,然后用POST传给他data内容,这应该怎么做啊?我是新手~~~
------解决方案--------------------

引用:
Quote: 引用:

php使用curl扩展模拟post提交。参考代码
/** <br /> * Send a POST requst using cURL <br /> * @param string $url to request <br /> * @param array $post values to send <br /> * @param array $options for cURL <br /> * @return string <br /> */ <br />function curl_post($url, array $post = NULL, array $options = array()) <br />{ <br />    $defaults = array( <br />        CURLOPT_POST => 1, <br />        CURLOPT_HEADER => 0, <br />        CURLOPT_URL => $url, <br />        CURLOPT_FRESH_CONNECT => 1, <br />        CURLOPT_RETURNTRANSFER => 1, <br />        CURLOPT_FORBID_REUSE => 1, <br />        CURLOPT_TIMEOUT => 4, <br />        CURLOPT_POSTFIELDS => http_build_query($post) <br />    ); <br /><br />    $ch = curl_init(); <br />    curl_setopt_array($ch, ($options + $defaults)); <br />    if( ! $result = curl_exec($ch)) <br />    { <br />        trigger_error(curl_error($ch)); <br />    } <br />    curl_close($ch); <br />    return $result; <br />}
然后怎么调用呢?

$data = json_encode(array(你要发送的data数组));
$rs = curl_post("http://199.199.99.199:8080/cloudTVPlatform/external/api?act=notifyNewDeveloper&PID=CloudTVDN&pversion=1.0&format=JSON", $data);
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn