why my response.body is empty and my device token in my backend is null?
171
You are capturing the FCM token correctly, just send it to your backend using a post method, and be prepared on your backend to capture this post. The FCMtoken is a string.
You can also send it along with the user ID for example, store them, then you can use them to send notifications to this user, because you have the userId and their device's FCMtoken.
Author by
Yara Abd
Updated on November 23, 2022Comments
-
Yara Abd over 1 year
I am Using Laravel for my App backend and want to send push notification to my flutter app my question is why response body is empty and device token in the backend is null?
static Future<http.Response> sendDeviceToken(String FCM_token) async{ SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); int id=sharedPreferences.getInt("id"); String myUrl = "$serverUrl/FCM"; var resp = await http.post(Uri.encodeFull(myUrl), headers: <String, String>{ "Accept": "application/json", }, body: jsonEncode(<String, String>{ 'FCM_token': FCM_token, 'id' : id.toString(), }), ); print("res.statusCode: ${resp.statusCode}"); print("res.body: ${resp.body}"); return resp; }
i print FCM_token inside this function and it print correct.
-
Huthaifa Muayyad over 2 yearsYou are capturing the token correctly, just send it to your backend, it's a string. Send it with the user ID and store them, then you can use them to send notifications to this device.
-
Frank van Puffelen over 2 yearsSounds like an answer @HuthaifaMuayyad ;-)
-
Huthaifa Muayyad over 2 yearsAs always, lots of love @FrankvanPuffelen <3
-
-
Yara Abd over 2 yearshow can i send it by using post method? @Huthaifa
-
Huthaifa Muayyad over 2 yearsSend it to your server, so your server can store it in your database. Write a simple
post
request from your flutter app. If you don't know how to do that, that is where I advise you to start looking :) check here. -
Huthaifa Muayyad over 2 yearsWhat happens when you run this code? Where is the problem?
-
Yara Abd over 2 yearsresp.body print empty and in the backend the value is null