【发布时间】:2017-12-11 16:53:14
【问题描述】:
我正在尝试在发布请求有效负载中传递数组。
url = http://IP:PortNo/index.php/v1/login
有效载荷:
data={ "terminal_id": "terminal_id", "api_login": "api_login", "api_key": "api_key", "merchant_code": "merchant_code" }
我所做的是:
$data = ['terminal_id' => $this->terminal_id , 'api_login' => $this->api_login,
'api_key' => $this->api_key , 'merchant_code' => $this->merchant_code];
$response = $this->client->post($url, array('data' => $data));
但我得到的回应是:
“未找到请求数据”
这意味着我的数据负载格式不正确。有什么想法吗?
【问题讨论】:
-
您是否尝试过使用 json_encode 将 $data 编码为 json?我过去曾做过类似
[ 'data' => json_encode($data) ]之类的事情,为了发送正确的正文。 -
是的,我滴滴
j$response = $this->client->post( $url, ['data' => json_encode($data) ] );但我得到了相同的结果Request data not found -
可能是
$this->client->post($url [ 'body' => json_encode([ 'data' => $data ]) ]);的形式?也许看看这个:stackoverflow.com/questions/22244738/…