如何使用Retrofit执行此请求?
问题描述:
我试图用改造执行的请求,但我得到404错误,而它使用的邮差工作:如何使用Retrofit执行此请求?
-
Authorization
标头值"key=123456789"
-
Content-Type
标头值application/json
并在体内:
{"notification": {"title":"Title","text":"Hello"},"to":"1234"}
该负责人SE将是这样的:
{ "multicast_id": 108,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{ "message_id": "1:08" }
]
}
我有这样的改造2代码:
public interface FcmApi {
@POST("/")
@Headers({"Content-Type: application/json", "Authorization: key=123456789"})
Observable<MyResponse> send(@Body String body);
}
MyResponse类
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyResponse {
public int success;
}
和测试:
String json = "{\"notification\": " +
"{\"title\":\"Title\",\"text\":\"Hello\"}," +
"\"to\":\"1234\"}";
api.send(json);
但我G等404错误。使用Postman可以在同一个例子中正常工作。
答
好像你正在使用key = 123456789。您应该使用Firebase控制台中的服务器密钥。另外“to”:“1234”应该是您设备上的真实Firebase注册ID。
他们只是例子,我使用的是正确的 –
您是否使用Retrofit并从Android或基于Java的服务器发送消息? – Taras
从Android到Android。 VíaFCM REST API –