android - Mailgun POST /messages API always throw 401 forbidden -


i trying send mailgun post /messages api request in android using retrofit library.

following retrofit request:

http post https://api:key-ffb26dc381eb57e40d4feafe05307f62@api.mailgun.net/v3/sandbox1f71fa7cde1d4b4c83312b5d259ba474.mailgun.org/messages

cache-control: no-cache
content-type: application/x-www-form-urlencoded
content-length: 148

from=excited+user+%3cmailgun%40sandbox1f71fa7cde1d4b4c83312b5d259ba474.mailgun.org%3e&to=vir.jain%40gmail.com&subject=hello&text=testing+awesomeness

response: http 401 https://api:key-ffb26dc381eb57e40d4feafe05307f62@api.mailgun.net/v3/sandbox1f71fa7cde1d4b4c83312b5d259ba474.mailgun.org/messages (1966ms)
server: nginx/1.7.9
date: mon, 15 jun 2015 10:00:37 gmt
content-type: text/html; charset=utf-8
content-length: 9
connection: keep-alive
www-authenticate: basic realm="mg api"
okhttp-selected-protocol: http/1.1
okhttp-sent-millis: 1434362440805
okhttp-received-millis: 1434362441086
forbidden

when try same request on postman, works & email sent properly. when sending using retrofit library android fails forbidden.

my retrofit api: @formurlencoded @post("/messages") public void sendemail(@field("from") string from, @field("to") string to, @field("subject") string subject, @field("text") string text, restcallback objectrestcallback);

base url is: https://api:key-ffb26dc381eb57e40d4feafe05307f62@api.mailgun.net/v3/sandbox1f71fa7cde1d4b4c83312b5d259ba474.mailgun.org

everything form url encoded. i'm not sure going wrong. can please me out whats wrong above api?

thank you, mahavir

i added following authorization header base64 encoded string of api key request, started working.

request.addheader("authorization", "basic "+getbase64string("api:key-your-api-key>"));

@selvin: sending wiki link :).


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -