What is the Java equivalent to use https://fcm.googleapis.com/fcm/send REST Api
401
means unauthorized, so no valid Authorization
header was sent.
And this line:
httpcon.setRequestProperty("Authorization: key", "AIza...iD9wk");
Is not equivalent to -H "Authorization: key=AIza...iD9wk"
. The first argument should be the header name, which is Authorization
:
httpcon.setRequestProperty("Authorization", "key=AIza...iD9wk");
In conclusion, you misunderstood how HTTP header is formatted. Basically the header name and value are separated by :
not =
.