php post json数据
2014-04-01 14:30
253 查看
function http_post_data($url, $data_string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string))
);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
ob_end_clean();
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($return_code, $return_content);
}
$url = "http://www.xxxx.com";
$data = json_encode(array('cmd'=>"Query_Ranking_Sys",'group'=>1,'room'=>0,'name'=>"RoomSvr",'value'=>array(0=>array('key'=>5,'beginindex'=>0,'count'=>10))));
list($return_code, $return_content) = http_post_data($url, $data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_string))
);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
ob_end_clean();
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($return_code, $return_content);
}
$url = "http://www.xxxx.com";
$data = json_encode(array('cmd'=>"Query_Ranking_Sys",'group'=>1,'room'=>0,'name'=>"RoomSvr",'value'=>array(0=>array('key'=>5,'beginindex'=>0,'count'=>10))));
list($return_code, $return_content) = http_post_data($url, $data);
相关文章推荐
- PHP如何通过Http Post请求发送Json对象数据?
- PHP获取post中的json数据
- php 模拟post json数据,并进行解析
- php-curl(模拟post,设置header,接收json数据)
- php下POST json数据无法解析问题
- PHP调用接口用post方法传送json数据
- php post json数据遇“&”字符被截断的解决方案
- php 通过curl post发送json数据实例
- php7游戏端以post发送json数据给php
- php模拟post提交提交json数据
- php获取post中的json数据
- php获取post中的json数据的实现方法
- [php]通过http post发送json数据
- 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换
- php获取post中的json数据的实现方法
- [php]通过http post发送json数据
- PHP调用接口用post方法传送json数据
- php获取post中的json数据的实现方法
- php中使用curl来post一段json数据
- php接收post的json数据