【发布时间】:2019-03-06 15:03:17
【问题描述】:
我想了解为什么“HTTPHEADER”选项没有被正确解释。发送进展顺利,但 Plivo 服务器无法读取我未以 JSON 形式到达的请求。
下面是助手Codeigniter:
function launchCall($from, $to, $position, $message){
$CI = &get_instance();
$CI->load->config('plivo');
$data = array("from" => $from, "to" => $to, "position" => $position, "message" => $message);
$data_string = json_encode($data);
$url = 'https://phlorunner.plivo.com/v1/account/YYYYYYYYYYYYYYYYYYYYYYYYYYYXXXXXXXXXXXXXXX';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json','Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_USERPWD, $CI->config->item('AUTH_ID') . ":" . $CI->config->item('AUTH_TOKEN'));
$result = curl_exec($ch);
return $result;
}
提前感谢您的帮助。
【问题讨论】:
-
你能澄清一下“解释不正确”是什么意思吗?为什么你认为你可以强制你发布数据的服务器接受某种格式?
-
在本地主机上?还是实时服务器?
-
我通过强制 Content-Type 从“邮递员”中尝试了它,并且效果很好。但是,当我从我们的实时服务器运行脚本时,它不起作用。根据从 Plivo 收到的信息,问题来自那里,但我不知道如何解决它。
标签: php json codeigniter curl