2

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!

Maycow Moura
  • 6,471
  • 2
  • 22
  • 19

1 Answers1

0

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.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
  • Thanks @Cheticamp. It worked for me! Unfortunatelly I plan to export my script as a App so I can't use external plugins. But that's a totally weird bug in Tasker. It's about %HTTPD and Content Type, cause %HTTPL shows the correct response length if I leave Content Type empty, but %HTTPD shows nothing. And if I set Content Type it doesn't send the parameters (I've tested it server-side too and it really doesn't) :( Anyway I just want to POST a file, so I don't even need to get the parameters back, I just need them to be sent, then I get just a "ok" as response. Thank you for helping! – Maycow Moura Mar 07 '17 at 20:12
  • I'm glad it worked. It looks to me like this defect has been in Tasker for a while. I don't think most POST requests look for a response other than the OK, so this probably doesn't come up a lot. – Cheticamp Mar 07 '17 at 20:16
  • Yeah, since I haven't found many questions about it I think people don't get this error often. Btw even to get that "ok" I'll need to write the file, 'cause if I use %HTTPD to get it I gotta set the content type, and if I set it, the parameters aren't sent.. – Maycow Moura Mar 08 '17 at 00:59
  • Yeah. Helped me a lot. Thanks – Maycow Moura Mar 08 '17 at 01:04