[Answered ]-How to send Token with POST request to Django REST api from Android App?

2đź‘Ť

You can save the Token in your shared preferences so you can access it everywhere in your app: so you dont have to give it with the intent everytime

final SharedPreferences prefs = this.getSharedPreferences(
“PACKAGE NAME”, Context.MODE_PRIVATE);

you can put the Token in it by

prefs.edit().putString(“Token”,tokenvalue).apply();

and retrieve it by

prefs.getString(“Token”,”DEFAULT VALUE”);

You can send the Token with your request by putting it in the Headers:

HttpPost httpPost = new HttpPost();
httpPost.setHeader(“authorization”,prefs.getString(“Token”,”DEFAULT VALUE”);

👤Jeroen Brock

0đź‘Ť

You need to include the token in the header you send with the request, where the random string is your token:

Authorization: Token 1af538baa9045a84c0e889f672baf83ff24
👤Mark Galloway

Leave a comment