我想使用xmlhttprequest通过我的PhoneGap / android应用程序访问服务网站,但是下面的代码返回“状态为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();
解决方法:
如果您的网站是由prestashop创建的,那么要使用Xmlhttprequest访问Web服务,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 =“”和ws_ke = key_genic_by_the_webservice
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。