当前位置:Gxlcms > PHP教程 > 发送POST请求在request中有以次data内容

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

时间:2021-07-01 10:21:17 帮助过:24人阅读

发送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提交。参考代码
/** 
* Send a POST requst using cURL
* @param string $url to request
* @param array $post values to send
* @param array $options for cURL
* @return string
*/
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);

$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
然后怎么调用呢?

$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);

人气教程排行