<?php
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('httpCode'=>$return_code, 'dataInfo' =>json_decode($return_content) );
}
$url = "http://www.qdhjzw.com/api";
$data = json_encode(array('key'=>"148cfbfe6a9b4b4b8a9c33e92045381s", 'info'=>"你是誰"));
// list($return_code, $return_content) = http_post_data($url, $data);
echo json_encode(http_post_data($url, $data));
PHP發送POST請求,以及返回json反斜槓處理
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.