question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

postTemplate is empty when it arrives to server

See original GitHub issue

Your Environment

  • Plugin version: 3.0.0-alpha.47
  • Platform: Android
  • OS version: 8.1.0
  • Device manufacturer and model: Mi A1
  • Running in Simulator: No
  • Cordova version (cordova -v): 8.1.2 (cordova-lib@8.1.1)
  • Cordova platform version (cordova platform ls): android 7.1.2
  • Plugin configuration options:
    let header = { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept-Language': 'es', 'Authorization': 'Bearer ' + token, 'User-Agent': this.userAgent }

    BackgroundGeolocation.configure({
      locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
      desiredAccuracy: BackgroundGeolocation.MEDIUM_ACCURACY,
      stationaryRadius: 30,
      distanceFilter: 20,
      interval: 30000, //180000
      fastestInterval: 20000, //120000,
      activitiesInterval: 10000,//20000,
      stopOnTerminate: false,
      startOnBoot: true,
      startForeground: true,
      pauseLocationUpdates: false,
      maxLocations: 20,
      stopOnStillActivity: false,
      notificationTitle: "SmartLogin Mobile",
      notificationText: "Activado en segundo plano",
      url: url + paraID,
      syncUrl: url + paraID,
      httpHeaders: header,
      postTemplate: {
        lat: '@latitude',
        lon: '@longitude'
      },
    });

    BackgroundGeolocation.checkStatus(res => {
      if (!res.isRunning) {
        BackgroundGeolocation.start();
      }
    })

Context

I’m working in an Ionic app which needs to register background geolocation using the plugin which works great. I have tried to use my custom http request with an interval to send the data when the app is in background (is working perfectly in foreground) but Android kills the process after 5 minutes approx.

So I have tried using the url, headers and postTemplate parameters of the configuration instead of my custom http code but postTemplate seems to be empty when it arrives to my server however the request is being successful.

Headers and url are working as expected so it has to be a problem with the postTemplate var.

Expected Behavior

postTemplate not being empty.

Actual Behavior

postTemplate var is empty so I can’t register the geolocation in my server

Possible Fix

Maybe some parse bug, I don’t really know.

Steps to Reproduce

Context

Debug logs

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mauron85commented, Nov 20, 2018

I read that it could be a problem

for most servers it’s important to send correct content-type. The plugin is already sending corrent-type. If you override it, your server will not be able to parse the content and that’s why you get empty response.

0reactions
pserna95commented, Nov 21, 2018

Already solved! It was the problem with the headers as you say. We didn’t need to send any ‘Content-type’ headers instead of that it’s necessary to parse the object in the backend.

Really grateful for your help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

POST request reaches server but empty - Stack Overflow
I'm setting up an API for a simple webservice and stumbled upon a problem. I use Ruby on Rails for the back end...
Read more >
Form data is empty when calling http.post() with ContentType ...
Hi I have facing same issue formData is showing empty in payload of Chrome browser while sending the formdata to server.
Read more >
get_page_template_slug() | Function
Gets the specific template filename for a given post. ... Returns an empty string when the default page template is in use.
Read more >
net/http - Go Packages
Package http provides HTTP client and server implementations. Get, Head, Post, and PostForm make HTTP (or HTTPS) requests: resp, err := http.
Read more >
Fixing Common Problems with CORS and JavaScript
They prevent JavaScript from obtaining data from a server in a ... The POST, PUT, and DELETE methods can add or change existing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found