2
我試圖用改造執行的請求,但我得到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可以在同一個例子中正常工作。
他們只是例子,我使用的是正確的 –
您是否使用Retrofit並從Android或基於Java的服務器發送消息? – Taras
從Android到Android。 VíaFCM REST API –