POST via $.ajax (with PhoneGap 2.6 and Zepto.js) on Android Woes - ajax

I am currently working on a PhoneGap app which is required to POST to a server (running Django). Unfortunately, we are not receiving the anticipated response when we perform this action: We get a 200 message with no data, rather than a 401 (unauthorized) with a json object.
Our javascript code is similar to: this code
The server-side python looks a bit like: this code
Any ideas?
Thank you!

I can not help you with your specific problem, but I can tell you that you will never get a 401 code back.
PhoneGap applications have an issue with it: they return code '0' instead of '401' for some reason. It is on their official JIRA:
PhoneGap JIRA
So whatever you find for solution for your issue, you will just get a new problem.

Related

I cannot access the file posted using FormData in Postman, in my Web API. HttpContext.Current.Request.Params["document"] returning NULL

I'm trying to post a simple file into my C# WEB API. Here is how it look in Postman:
This SO thread make it look easy to access the file. It seems that I only need the instruction:
var fileToUpload = HttpContext.Current.Request.Params["document"];
However when I hit the endpoint and I debug, fileToUpload is coming null.
What's wrong??
Thank you
For some reason, even if it supposed to work with code HttpContext.Current.Request.Params["document"]; following this thread, it didn't work for me. What actually worked, is using HttpContext.Current.Request.Files["document"];

Laravel API throws FileNotFoundException when accessed through an android app

I'm working on an API using Laravel 5.2. I have disabled the csrf token by commenting \App\Http\Middleware\VerifyCsrfToken::class in kernel.php. If I access my API with postman everything works like charm but when using an android app I get FileNotFoundException. Please help. I can post the code and other details if you want. Thanks in advance.
Sorry It was an issue on the android side not on Laravel. It is resolved now.
The issue was that I was setting the HTTP CODES myself in Laravel. So the problem was If i set a code in range 4XX( like 404), android will consider it as an error and show fileNotFoundException and neglect the stream in the connection. So changing getInputStream to getErrorStream resolved the problem. getErrorStream reads the stream even if the response code is some kind of error like 404,422 ,etc. I hope the explanation is sufficient.

WP8.1 c# Onedrive SDK : download badrequest

I have a project which now doesn't work when I download binarie from onedrive like PNG. I got a bad request in query response. I take some backup and they have the same problem. This was working few days ago I have not modify anything. Is there a changne in the api ? I download xml with no problem whith same query.
I try to test apigee console and it seems to work. Anyone has same problem ? Got solution ?
THANKS a lot
I go this response from api :
StatusCode: 400, ReasonPhrase: 'Bad Request'
For those that find their way here, the problem in question is a result of some proxy servers rejecting the URLs when they contain single path segments with more than 260 characters. Unfortunately this is possible with the URLs that the OneDrive API generates, and so we're investigating changes to resolve this kind of problem.
The issue can be tracked at https://github.com/OneDrive/onedrive-api-docs/issues/143

How to debug a failed ajax request in google chrome?

I have a web application that crashes on ajax requests with google chrome (it works with every other web browser it was tested it). After debugging I found that the error is caused by response.responseText being undefined. The xhr object looks like this:
argument: undefined
isAbort: false
isTimeout: undefined
status: 0
statusText: "communication failure"
tId: 3
In debugger in the 'network' tab I get "(failed)", however all the headers are there and I can even copy into clipboard the response body (which is a valid JSON).
My question is - how can I debug this problem? Where to find additional information, what causes this request to fail?
I finally found the solution to my problem : AdBlocks, when it blocks an ajax request, it just says "communication failure".
The first thing I would double-check is that the data coming back from the response is valid JSON. Just pass it through a JSON validator like this online JSONLint: http://jsonlint.com/
I assume that you are using something like jQuery to make your AJAX requests. If so, then make sure that you are using the development version of that library. Now that you are using the development version (uncompressed) of the script, find the particular function that you are using (eg. $.ajax) and then, within the Chrome inspector, insert a breakpoint in the code where the AJAX response is first handled (eg. https://github.com/jquery/jquery/blob/master/src/ajax.js#L579). Then proceed to step through the code, inspecting various return-values to see exactly what is going wrong.
If you are not using something like jQuery to make AJAX calls, then I'd recommend using a framework to avoid possible cross-browser compatibility issues like you might be experiencing right now.

Ruby fb_graph app_request, or Request Dialog

I'm trying to do an app request, but my requests do not apear in the notification (the globe icon) and I don't know what to do more.
Just to confirm that i've done everything ok, I have followed the JS SDK Request Dialog example:
http://developers.facebook.com/docs/reference/dialogs/requests/
At first time it seems to work ok, and I have a list of my request, but can't see none in facebook.
What I have done so far:
used the fb_graph gem ( https://github.com/nov/fb_graph )
u = FbGraph::User.me(User.find(2).fb_access_token)
u.app_request!(:message => 'punk message')
After that if I do u.app_requests, I can see a list of requests.
As this seems not to work I after tried the Facebook JS SDK, and the result is the same.
My Question is: What am I doing wrong, or missing something?
Thank you
The more I'm around it, the more I'm favoring the Javascript SDK over server side code. Is there a reason for your app to require to do anything serverside, or can you accomplish the same thing client side? Can you give us an example of the Javascript code you tried that failed?

Resources