admin管理员组文章数量:1336112
I folks,
I'm working on a Phonegap application and the Sencha framework.
I try to reach a protected server but the authentication failed with Android (but not with iOS). I use the code below :
Ext.Ajax.request({
url:"http://user:[email protected]/query.json",
method: 'GET',
// I tried to send the header directly but it didn't work too
headers: {
"Authorization": "Basic s2dh3qs76jd2hqjsdh=="
},
success: function (result, request) {
alert(result);
},
failure: function ( result, request) {
for(var key in result)
alert(result[key]);
}
});
The error message says me that an HTTP digest is required...
Just to know:
- Internet connexion is fine
- The same code works with a local file and other external APIs
- I don't know how to explore Javascript objects in the LogCat so excuse my disgusting
alert(result[key])
Thank you guys, you all rock!
I folks,
I'm working on a Phonegap application and the Sencha framework.
I try to reach a protected server but the authentication failed with Android (but not with iOS). I use the code below :
Ext.Ajax.request({
url:"http://user:[email protected]/query.json",
method: 'GET',
// I tried to send the header directly but it didn't work too
headers: {
"Authorization": "Basic s2dh3qs76jd2hqjsdh=="
},
success: function (result, request) {
alert(result);
},
failure: function ( result, request) {
for(var key in result)
alert(result[key]);
}
});
The error message says me that an HTTP digest is required...
Just to know:
- Internet connexion is fine
- The same code works with a local file and other external APIs
- I don't know how to explore Javascript objects in the LogCat so excuse my disgusting
alert(result[key])
Thank you guys, you all rock!
Share edited May 15, 2012 at 10:58 casperOne 74.6k19 gold badges189 silver badges260 bronze badges asked Nov 9, 2011 at 16:56 PirhooPirhoo 6808 silver badges21 bronze badges 2- Nope, I didn't find the solution. Sorry. – Pirhoo Commented Dec 19, 2012 at 12:15
- Any solution for this? How to disable web-security for Android application using Eclipse? – Mrunal Commented Jun 16, 2014 at 12:14
5 Answers
Reset to default 3I agree with @Mariano. Why can't you try it in the browser and then deploy as an app with phonegap. The cross-domain problem can be solved by starting google chrome from the terminal by this mand google-chrome --args --disable-web-security
Check out this link for more information
http://www.senchatouchbits./7/cross-domain-ajax-requests.html
I had endless trouble with authenticating my ajax requests but I finally got it to work. I got a basic base64_encode algorithm of the net. Then all you need to to is adjust your header as follows
Ext.Ajax.request({
url:'yourwebserviceurl',
method:'GET',
headers: {
Authorization: 'Basic '+ base64_encode(form.username+':'+form.password)
},
success: function(response){
//Ext.Msg.alert(response.responseXML);
console.log(response.responseText);
},
failure: function(response){
//console.log('Success response: ' + response.responseText);
Ext.Msg.alert('b');
}
});
This worked for a basic soap service !
I have the same problem... where you able to fix it?
Btw... you have to set the user and password like this:
Ext.Ajax.request({
url:"http://api.website.fr/query.json",
method: 'GET',
username : 'user',
password : 'password',
// I tried to send the header directly but it didn't work too
headers: {
"Authorization": "Basic s2dh3qs76jd2hqjsdh=="
},
success: function (result, request) {
alert(result);
},
failure: function ( result, request) {
for(var key in result)
alert(result[key]);
}
});
Use console.log to see what a js object have, you allways must try the app in a browser with a debbuger like Firebug to detect issues more easy.
To your problem in Android, make sure this line is in phonegap app manifest file: < uses-permission android:name="android.permission.INTERNET" >< /uses- permission >
Good Luck!
This is a cross domain request problem. You have to modify your code to create a JSONP request
Ext.util.JSONP.request({
url: 'http://url',
callbackKey: 'callback',
callbackName: 'callback',
model: 'Model',
params: {},
callback: function(result){
var shows = result.data;
},
});
Keep in mind that you have to adapt also the server side, so that the respone for it is a jsonp result (callback)
本文标签: javascriptPhonegapSenchaAndroidajax request with a basic access authentication failledStack Overflow
版权声明:本文标题:javascript - Phonegap + Sencha + Android : ajax request with a basic access authentication failled - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742403920a2468432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论