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

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:
HTTP POST works, it returns the response "text: {}" but doesn't return any parameter:
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!

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.

Related

How to solve "CORS policy: The 'Access-Control-Allow-Origin' header has a value that is not equal to the supplied origin.'?

I am working on an ionic 3 Project. When i run the project on android i get the following error.
Access to XMLHttpRequest at 'https://baseurl.com/api' from origin 'file://' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://baseurl.com' that is not equal to the supplied origin.
I started getting this error from last week monday and until then it was working fine.
In the requests(POST/GET) i am using the following headers
headers.append('Content-Type', 'application/x-www-form-urlencoded');
or
headers.append('Content-Type', 'application/json');
According to the ionic documentation CORS Errors, what i understood was that there are changes has to be done from the server side. Is there anything can be done from the ionic side? What could be the issue?
Two problems with your issue. One is more simple, and one is that https://baseurl/api doesn’t have a .com, or a .anything, so it is mostly invalid. The second that CORS is a necessary evil to deal with. You are going to have to set up a local server do deal with it, as some requests cannot be made by items being served by a file:// protocol. Local servers can be set up a variety of ways, depending on your situation. It would be helpful to explain how you are running it, and what tools you are using, so that we may be able to better help you.
The issue is due to a chrome update and for further details about the issue please refer This.
Update the 'Android System Webview' in google play store to the latest version and this issue will go away

Using prestashop webservices in Android

I have a problem with PrestaShop web services. I'm creating an Android app for one service. I configured everything in panel properly, gave corresponding permissions (e.g. GET, POST, DELETE, PUT for "carts"). When I'm sending GET request I get a response. Everything works. Problems start when I try to use e.g. DELETE, PUT or POST.
I followed this tutorial:
http://blog.belvg.com/prestashop-web-services.html
I make my test requests via site https://www.hurl.it/
Trying to update something, for instance, cart number 1 I get it by:
http:// MYDOMAIN .pl/api/carts/1?schema=synopsis
Then I edit some fields and try to send it back by PUT method and XML as the parameter, but I get:
<H1>400 Bad Request</H1>
Your browser sent a request that this server could not understand.
Trying to add a new cart does not work also. I try it by getting blank XML:
http://MYDOMAIN.pl/api/carts?schema=blank
That gives me blank XML. When I will not fill this XML and I try to send it back by POST I get the message:
<message>
<![CDATA[Internal error. To see this error please display the PHP errors.]]>
</message>
What means possibly it can work. But when I will fill it with data, I get again 400... Any Idea what I can be doing wrong? Did I miss something?
P.S. I have access to an only panel (not server) and can do things only via panel and send requests.

SendLogsRequestListener failure in worklight

I am re-implementing an existing worklight system. We have already have a hybrid version. We have decided to re-implement the Client side in pure native. The native client seems work fine.
However, the server seems to be quite unstable - sometimes we don't get a server response after invoking an adapter, sometimes we do get. I have checked the DDMS/Android console. And a Error/Exception was found. Any comments would be appreciated!
com.worklight.common.Logger$SendLogsRequestListener(4274): Logger$SendLogsRequestListener.onFailure in Logger.java:1726 :: Failed to POST data from file /data/data/${APP_NAME}/files/analytics.log.0.send due to: HTTP response code: 500
On a successful adapter call or WLClient connection to the server, the client will attempt to automatically send logs to the server. It looks like something bad is happening on the autosend for adapters. A temporary workaround would be to disable this auto sending behavior by calling
WL.Logger.setAutoSendLogs(false)
But you can only use this call if you do not wish for logs to be sent automatically. If you do wish to have this working properly, I'd suggest opening a PMR so that it can be determined if this is an error in your application or an actual defect.

Android Retrofit Causes Socket Timeout Exception

I am making a POST call to a tomcat server running Struts2 using the retrofit library on an Android Galaxy S3 (/Nexus 7) device. The POST call fails. The tomcat log shows Socket timeout exception.
The same POST using the exact same headers done via curl does not have any issues. I verified that the data on the wire matches using charles proxy.
Any tips/ideas on debugging this issue.
The post call is as follows
#POST(Constants.URL_GET_ORDER_LIST_BASE)
void getCardOrderList(#Body GetOrderListRequest getOrderListRequest, Callback<GetOrderListResponse> cbGetOrderListResponse);
Please let me know if I need to add more information to explain this better.
Adding Square's OKHTTP library into the libs folder fixed the issue.
I was having SocketTimeoutExceptions too. Pay attention to always add the final slash to your POST call.
Example:
BAD
#POST("/customers")
GOOD
#POST("/customers/")
My mistake was just this :)

What is Apache-HttpClient/UNAVAILABLE error (Android, Google App Engine)?

I am confronting myself with a problem that I do not know how to interpret. I am doing a project using Android and Google App Engine. When I am trying to save information in Google App Engine's Big Table, directly from the servlet (hardcoded) - the save is performed with no problem. But when I am trying to save data from my Android device, the save is not performed and the log indicates Apache-HttpClient/UNAVAILABLE error. To be more specific:
405 55ms 0kb Apache-HttpClient/UNAVAILABLE (java 1.4)
82.155.246.249 - - [10/Jun/2013:05:20:59 -0700] "POST /servletnamehere HTTP/1.1" 405 306 - "Apache-HttpClient/UNAVAILABLE (java 1.4)" "appnamehere.appspot.com" ms=56 cpu_ms=21 cpm_usd=0.000034 app_engine_release=1.8.0 instance=00c61b117cede3f754aa1ece730dc88287a20199
I have seen that 405 HTTP error appears in the context of a POST method ( "405 errors often arise with the POST method. You may be trying to introduce some kind of input form on the Web site, but not all ISPs allow the POST method necessary to process the form." ) => indeed, I am trying to perform add (the object is a JPA Entity) in the database using a POST method. The data I am receiving from my Android device is serialized, through an input stream (in my case, working with JSON is not an option, these are the specifications).
Also, 306 HTTP error reffers to switch proxy. While the porevious error might be a bit intuitive, this one is beyond my student knowledge.
I have followed the instructions of this tutorial (http://trumpy.cs.elon.edu/joel/sigcse2011/), which is indeed what I need, but I really cannot figure out what I did wrong. I took again the procedure, stept by step, but I don't see the flaw.
Any help will be indeed appreciated. If I should post some code, I'll gladly do it.
Best wishes,
Cropcircles
LATER EDIT:
Now I get 417 HTTP error expectation failed. I have seen that I am supposed to set a certain parameter on false, but this workaround was available only for .NET. Is there anyone who knows what's the correspondent of the following, in Java? I am really really confused.
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
This is not an answer, but is too long for a comment and may be helpful, so here goes...
First, it's hard to tell what's going on here because there is limited info. Try to post more of the logging either on the client or on the server. Go to the server console and get more info, for instance, or add debugging in the client. I'd start by trying to make the POST from a debug/testing tool like hurl.it: http://www.hurl.it/ (hurl is a nice web front end to a command line HTTP client named curl, see curl itself if you want a more advanced peek). That way you can test and poke around and make SURE your server side works as you expect with a generic client. Then build other clients (like Android).
Second, "Apache-HttpClient/UNAVAILABLE" is not an error, it's just the user-agent String -- so ignore that part. (UNAVAILABLE is where the version typically is, but some impls don't have access to the version sometimes, it seems.)
Third, the 405 response code IS an error, it means POST is not allowed at the server you are trying to POST to. That can either be because POST is not allowed at all on said server, or you're violating some security policy (such as same origin).
If it's AppEngine, first check the APP you are using and make sure it supports POST (look for info on how to do POST at AppEngine to solve, for instance: google app engine: 405 method not allowed). When you say you can do it directly from a "servlet," do you mean that a POST from a different client works? (Servlet is a server side technology, so that's a little confusing.) If so then make sure your Android app is doing the client part the same way to the same host (multipart vs urlencoded, etc).
For a little more on the security stuff, which could be involved, see this post: Google App Engine + jQuery Ajax = 405 Method Not Allowed.
I've had the same trouble and in my case It was an error due to no write permission on server side area.
I was following an android test to write on a file a value transmitted in async way via POST method.
Apache received the POST request but was not able to write the data on the file due to security permission on it.

Categories

Resources