473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Xmlhttprequest returns 401 on phonegap/android application

I want to access to the service web via my PhoneGap/android application with xmlhttprequest, but the code below returns "Status is 401".
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5.       <title>PhoneGap</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7.   <script type="text/javascript" charset="utf-8" src="js/Config/phonegap-0.9.3.js"></script>
  8.  
  9.  
  10.   <link rel="stylesheet" href="css/jquery/jquery.mobile-1.0a1.min.css" />
  11.   <link rel="stylesheet" href="css/Style.css" />
  12.   <script src="js/Config/jquery-1.4.3.min.js"></script>
  13.   <script src="js/Config/jquery.mobile-1.0a1.min.js"></script>
  14.   <script src="jquery.form.js"></script>
  15.      <script src="js/Config/jquery-1.7.1.js"></script>
  16.   <script src="js/Config/jquery-1.7.1.min.js"></script>
  17.  
  18. <script language="javascript">
  19.  
  20. var request = new XMLHttpRequest();
  21.        request.open("GET","http://www.patisserie-orient.fr/prestashop/prestashop/api/products/63",true);
  22.        request.onreadystatechange = function() {
  23. alert("Status is "+request.status);
  24.            if (request.status == 200 || request.status == 0){
  25. response  = request.responseXML.documentElement;
  26. //alert("b");
  27. itemDescription = response.getElementsByTagName('price')[0].firstChild.data;
  28. alert ( itemDescription );
  29. //$("#dropdownlist").append("<hr>" + itemDescription + "<hr>");
  30.            }
  31.        }
  32.        request.send();
  33. </script>
  34. </head>
  35. <body>
  36. <div id="dropdownlist" />
  37. </body>
  38. </html>
  39.  
  40.  
Can anyone help me explaining the error or offering me a solution?
Feb 25 '12 #1

✓ answered by Dormilich

it seems that in Android an XMLHttpRequest does not trigger such a modal window (why should it?). but you can pass username and password in the URI itself.

8 3420
Dormilich
8,658 Expert Mod 8TB
401 means that you’re not authorized to use that resource. (list of HTTP status codes)
Feb 26 '12 #2
I know that, but how can I resolve the problem?
Feb 26 '12 #3
Dormilich
8,658 Expert Mod 8TB
log in. when I tried to open the URI in the browser, it asked for username/password.
Feb 26 '12 #4
yes, I enter them (there is the username and password of my service web), but also req.status=401.
Feb 26 '12 #5
Dormilich
8,658 Expert Mod 8TB
the XMLHttpRequest has to do this verification, too.
Feb 26 '12 #6
If I test the code in Internet Explorer, it displays a window to enter user and password then returns 200, but android does not show this window and returns directly 401!!
Feb 26 '12 #7
Dormilich
8,658 Expert Mod 8TB
it seems that in Android an XMLHttpRequest does not trigger such a modal window (why should it?). but you can pass username and password in the URI itself.
Feb 26 '12 #8
It resolved :)
Expand|Select|Wrap|Line Numbers
  1. request.open("GET","http://patisserie-orient.fr/prestashop/prestashop/api/products/63?ws_key="+"keywebservice+"&PHP_AUTH_USER="+"password",true);
  2.  
Feb 26 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dave | last post by:
I want to design/develop an windows application that can query multiple websites (XmlHttpRequest), call number of 3rd party external webservices (SOAP) and parse/process the data and display it to...
1
by: dave | last post by:
I want to design/develop an windows application (C#) that can query multiple websites (XmlHttpRequest), call number of 3rd party external webservices (SOAP) and parse/process the data and display...
5
by: Jeff | last post by:
Is there a standard way of getting the HTMLDocument object representation of a remote page using Javascript? If I request an HTML page, the xmlHttpRequest returns either text or an XMLDocument. I...
1
by: Ronald Green | last post by:
Hi all, I'm trying to write a js function that uses XMLHttpRequest against a web application. Sometimes I get a 302, and the XMLHttpRequest automatically redirects. What I want to...
8
rpnew
by: rpnew | last post by:
HI, I'm working with PHP/MySql... on one page i've used this XMLHttprequest object. Now i'm developing the system on FC4/FireFox.. on my machine it works fine but if i try to access it from...
8
by: sbettadpur | last post by:
hello I am using xmlHttpRequest method in my application, this method is giving problem in the following browsers 1) Internet Explorer 7 2) Mozila Firefox(2.0.0.16) I got solution for...
1
by: ankitjain100 | last post by:
I want to develop mobile application, but my problem is how and from where to start development. I am beginner in software development. Please guide me how can i start mobile application...
0
Todd Faisal
by: Todd Faisal | last post by:
A quick overview of the popular mobile application development platforms: Android application development Android is developer’s dream – it is free, open sourced, and it is developed and endorsed...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.