我试图发送一个帖子请求,标题是json,响应也是json。到目前为止我尝试了什么。这始终会返回status
代码400
。我做错了什么?谢谢
private function requestPOST($url,$data)
{
App::uses('HttpSocket', 'Network/Http');
App::uses('Json', 'Utility');
$this->layout = 'default';
$this->autoRender = true;
$HttpSocket = new HttpSocket();
$jsonData = json_encode($data);
$request = array('header' => array('Content-Type' => 'application/json'));
debug($url);
$response = $HttpSocket->post($url, $jsonData, $request);
debug($response->code);
//$this->render('index');
$jsonString = json_decode($response['body'], true);
debug($jsonString);
return $jsonString;
}
答案 0 :(得分:1)
我已经解决了自己。我正在做两次json_encode
$ data。