Search code examples
androidajaxxmlhttprequesttasker

Tasker App: Why my HTTP POST is not sending parameters?


I'm making a simple HTTP POST request using Tasker app, it's working fine but somehow it's not sending my arguments. HTTP GET is working fine. What am I doing wrong?

The only thing the server does is JSON stringify all received parameters and return them like: Text: { parameters }

HTTP GET is working:

enter image description here

HTTP POST works, it returns the response "text: {}" but doesn't return any parameter:

enter image description here

Now sometimes it shows "Bad Request Error 400"

I've tested it with another server and this issue persists...

Here's a fiddle to send get and post requests to the same server and both work.

I've exported my task as xml for you to test: You can download it here

Thanks in advance guys!


Solution

  • I have done a little testing with what you have supplied. It appears that your post parameters are making it to the server but %HTTPR is not getting populated. The Tasker documentation says that this variable will be populated if the response is "text-based", but this does not seem to be the case. I may not know what Tasker considers to be "text-based", but I have tried "text/plain" and "text/html" with no luck.

    The work-around that I have come up with is to put the response into a file using the "Output File" field of the post task. (Leave "Content Type" blank or this won't work.) You can then read the file into a variable and do what you need to.

    This is either a defect in Tasker, incorrect documentation, or just a misunderstanding of what it takes to make it work. This work-around, however, will get you what you need.

    Here is a link to a GitHub repository with the updated task export. You may need to change the output file name/location to work with your device.


    Update: Since I posted the above solution, I have run across a Tasker plugin called "RESTask for Tasker". Evidently, Tasker has enough issues with HTML requests that a separate plugin was needed. I have tested this plugin with POST and it does work, so this is another way to go. The plugin is available on the Google Play store.