使用下面的curl能访问restful (帐号和密码做了修改)
curl -v -H "Content-type:application/json" -X GET -u eb10ec208300b6481bf936965e:0feaaae85e2406d07073588bdb -k -i https://www.azitainno.com/v1.0.2/dev_registration/1 -d "{\"mac\":\"b8e8563b5832\", \"m12nc\":\"867000123817\", \"hash\":\"554812176edc7c80d9a915e32a240b65\"}"
改写成plus.net.XMLHttpRequest,却无法使用,请问我的问题出在什么地方:
testRestful = function() {
var d = {
"mac":"b8e8563b5832",
"m12nc":"867000123817",
"hash":"554812176edc7c80d9a915e32a240b65"
};
alert(JSON.stringify(d));
var xhr=new plus.net.XMLHttpRequest();
xhr.onreadystatechange = function () {
switch ( xhr.readyState ) {
case 0:
alert( "xhr请求已初始化" +xhr.responseText);
break;
case 1:
alert( "xhr请求已打开" +xhr.responseText);
break;
case 2:
alert( "xhr请求已发送" +xhr.responseText);
break;
case 3:
alert( "xhr请求已响应"+xhr.responseText);
break;
case 4:
if ( xhr.status == 200 ) {
alert( "xhr请求成功:"+xhr.responseText );
} else {
alert( "xhr请求失败:"+xhr.readyState + xhr.responseText);
}
break;
default :
break;
}
}
xhr.open('GET', 'https://www.azitainno.com/v1.0.2/dev_registration/1', 'eb10ec208300b6481bf936965e', '0feaaae85e2406d07073588bdb');
xhr.setRequestHeader("Content-type", "application/json");
// xhr.setRequestHeader('Authorization', 'Basic ZWIxMGVzNTcxNjk2NWUyODE6MGZlYWE5MjRh1ZTI0MDZkMDcwNzM1ODhiZGI5ZTE=');
xhr.send(JSON.stringify(d));
谢谢高人的答复。
2 个回复
rodgerz
mui ajax api
bigcoolfish (作者)
mui的ajax就是封装了plus.net.XMLHttpRequest的,还仅仅支持get和post