发送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);