【发布时间】:2019-01-25 05:03:27
【问题描述】:
在这里挠头。这段代码有什么问题?出于某种原因,Expo 的响应是 404。我以错误的方式向他们发送东西,但不知道该怎么做!
EXPO 文档在这里:https://docs.expo.io/versions/latest/guides/push-notifications#http2-api
我的代码:
$client = new Client(); //GuzzleHttp\Client
$url = 'https://exp.host/--/api/v2/push/send';
$data = [
'to' => array('ExponentPushToken[gaXXXXXXXXX_Oi4J1b9OR]'),
'title' => $notification->title,
'body' => $notification->body
];
$headers = [
'Accept' => 'application/json',
'Accept-Encoding' => 'gzip, deflate',
'Content-Type' => 'application/json',
];
$response = $client->post($url, ['form_params' => $data, 'headers' => $headers]);
dd($response);
得到以下错误:
Client error: `POST https://exp.host/--/api/v2/push/send` resulted in a `404 Not Found` response: Not Found
注意:在 guzzle 帖子中将 'form_params' 更改为 'multipart' 会给我带来与 expo 不同的错误:
A 'contents' key is required
最后,将 'form_params' 更改为 'query' 给了我:
Client error: `POST https://exp.host/--/api/v2/push/send?to%5B0%5D=ExponentPushToken%5XXXXXXXXXX_Oi4J1b9OR%5D&title=asdasd&body=asdasdasd` resulted in a `400 Bad Request` response: {"errors":[{"code":"API_ERROR","message":"child \"to\" fails because [\"to\" is required], \"value\" must be an array."} (truncated...)
【问题讨论】:
-
你用的是什么版本的 Guzzle?
-
@Ross,最新的,所以 Guzzle 6> 我想...