2016-08-14 75 views
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可以在同一个例子中正常工作。

回答

0

好像你正在使用key = 123456789。您应该使用Firebase控制台中的服务器密钥。另外“to”:“1234”应该是您设备上的真实Firebase注册ID。

+0

他们只是例子,我使用的是正确的 –

+0

您是否使用Retrofit并从Android或基于Java的服务器发送消息? – Taras

+0

从Android到Android。 VíaFCM REST API –