通过http post发送json数据
2015-01-15 17:38
537 查看
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://xx.xx.cn";
$data = json_encode(array('a'=>1, 'b'=>2));
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://xx.xx.cn";
$data = json_encode(array('a'=>1, 'b'=>2));
list($return_code, $return_content) = http_post_data($url, $data);
相关文章推荐
- PHP通过Http Post请求发送Json对象数据?
- [php]通过http post发送json数据
- [php]通过http post发送json数据
- HttpClient通过Post方式发送Json数据
- [php]通过http post发送json数据
- [置顶] HttpClient通过Post方式发送Json数据
- PHP如何通过Http Post请求发送Json对象数据?
- HttpClient通过Post方式发送Json数据
- [php]通过http post发送json数据
- [php]通过http post发送json数据
- PHP如何通过Http Post请求发送Json对象数据?
- Multipart/form-data POST文件上传详解 理论 简单的HTTP POST 大家通过HTTP向服务器发送POST请求提交数据,都是通过form表单提交的,代码如下: <form me
- 通过httpClient发送json格式数据请求
- CC3200 HTTP Cli通过POST的方式把json数据提交给服务器出现的问题
- 通过 HTTP POST 发送二进制数据
- iOS通过ASIHttpRequest接收php端发送的Json数据
- php 通过curl post发送json数据实例
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)
- HttpClient通过Post方式发送Json数据
- Android系列之网络(三)----使用HttpClient发送HTTP请求(分别通过GET和POST方法发送数据)