【问题标题】:Xmlhttprequest returns 401 on phonegap/android applicationXmlhttprequest 在 phonegap/android 应用程序上返回 401
【发布时间】:2012-03-14 23:16:21
【问题描述】:

我想通过我的 PhoneGap/android 应用程序使用 xmlhttprequest 访问服务网站,但下面的代码返回“状态为 401”。

 var request = new XMLHttpRequest();
                   request.open("GET","http://www.mysite.fr/api/customers/2",true);
                   request.onreadystatechange = function() {
   alert("Status is "+request.status);
                           if (request.status == 200 || request.status == 0){
   response  = request.responseXML.documentElement;
   itemDescription = response.getElementsByTagName('lastname')[0].firstChild.data;
   alert ( itemDescription );
                           }
                   }
                   request.send();

谁能帮我解释错误或提供解决方案?

【问题讨论】:

  • Well 401 是未经授权的错误。该网站需要您登录吗?
  • 不,该网站不需要登录,但网络服务需要密钥

标签: android xml cordova xmlhttprequest


【解决方案1】:

如果你的网站是prestashop创建的,那么使用Xmlhttprequest访问webservice,request.open应该是这样的:

request.open("GET","http://www.mysite.fr/api/customes/2?PHP_AUTH_USER="+PHP_AUTH_USER+"&ws_key="+ws_key,true);

与:PHP_AUTH_USER="" and ws_ke=key_generated_by_the_webservice

【讨论】:

    猜你喜欢
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2013-07-11
    相关资源
    最近更新 更多