【发布时间】:2016-08-14 17:07:08
【问题描述】:
我正在尝试使用 Retrofit 执行请求,但在使用 Postman 工作时出现 404 错误:
-
Authorization标头,值为"key=123456789" -
Content-Type标头,值为application/json
在体内:
{"notification": {"title":"Title","text":"Hello"},"to":"1234"}
响应会是这样的:
{ "multicast_id": 108,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{ "message_id": "1:08" }
]
}
我有这个 Retrofit 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);
但我收到 404 错误。使用 Postman 可以在相同的示例中正常工作。
【问题讨论】:
标签: retrofit2