Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting 401 UnAuthorised with Cordova jquery ajax call , Upto Phonegap 1.4 it was working fine

I have upgraded my project to Phonegap 1.4 to Cordova 1.8.1. Ajax call to webservice was working fine with 401 Unauthorized , when I am passing invalid username / password in Phonegap 1.4.

After up gradation it is not working , I am not getting any response and web service stay there.

If change code to Phonegap 1.4 , it starts working.

Please help

like image 906
Raajeev H Dave Avatar asked Jan 15 '23 18:01

Raajeev H Dave


1 Answers

I've had this problem for the last couple months and finally figured it out.

First of all, the temporary workaround that we used was to implement a timeout period on the request. That worked, but the response was always a 404. We didn't know if it actually failed authentication, or if our services were down. Not an acceptable workaround for our system.

Finally, after MUCH googling, I found the actual problem.

When a 401 gets returned, (which is a Basic Authentication, authentication failure), it adds a header to the response, called "WWW-Authenticate". This tells the browser to prompt the user to try and login. iOS webview doesn't know what to do with that, so that's why the application hangs.

From your service, all you need to do is remove the WWW-Authenticate header, and you should start to see the 401's in your error function.

like image 71
ganders Avatar answered Jan 31 '23 07:01

ganders