使用验证用的Ajax.Request [英] Using Authentication with Ajax.Request

查看:162
本文介绍了使用验证用的Ajax.Request的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个使用的Ajax.Request连接到使用基本身份验证的Web服务的Palm的WebOS应用程序。要发送的用户名和密码,我只是将其包含在URL(即的http://用户名:密码@ IP地址:端口/ ),它的工作原理非常好,希望当密码包含任何非字母数字字符等的(例如,我有一个用户发邮件给我最近谁包含一个@和&放大器;在他的密码,而且他无法连接,因为这些符号并没有获得正确解析为URL)。有没有解决在发送该URL的凭据,以便我可以允许用户使用的东西不仅仅是字母数字等在他们的密码什么办法?

 变种的用户名= cookie.get()服务器[this.serverIndex] .username。
    VAR密码= cookie.get()服务器[this.serverIndex]。密码。
    this.auth ='基本'+ Base64.en code(用户名+:+密码);
    VAR的baseUrl =HTTP://+ URL +:+端口+'/ GUI /';
    this.baseUrl =的baseUrl;


    VAR请求=新的Ajax.Request(this.tokenUrl,{
        方法:'得到',
        超时:2000,
        标题:{
            授权:this.auth
        },
        的onSuccess:successFunc,
        onFailure:this.failure.bind(本)
    });
 

响应是(我删除的网址出于安全原因):

  {请求:{选项:{法:得,异步:真正的的contentType:应用/的X WWW的形式 - urlen codeD,编码:UTF-8,参数:{},evalJSON:真实,evalJS:真,超时:2000年,头:{授权 :基本c3VubW9yZ3VzOmZyb2dneUAlMjY =},运输:{的readyState:4,onloadstart:空,withCredentials:假的onerror:空,onabort:空,状态:401, responseXML的:空的onload:空,onprogress:空,上传:{onloadstart:空,onabort:空的onerror:空的onload:空,onprogress :空}状态文本:,responseText的:,UNSENT:0,开张:1,HEADERS_RECEIVED:2,加载:3,DONE:4}网址:
 

解决方案

发送基本身份验证信息与标题: 的http:// coderseye .COM / 2007 /如​​何对DO-HTTP的基本认证功能于ajax.html

  VAR权威性='基本'+ Base64.en code(用户+:+通);
Ext.Ajax.request({
    网址:网址,
    方法:GET,
    标题:{授权:AUTH}
});
 

I currently have a Palm WebOS application that uses an Ajax.Request to connect to a web service using basic authentication. To send the username and password, I simply include it in the url (i.e. http://username:password@ip-address:port/) which works exceedingly well, expect for when the password contains anything other than alphanumeric characters (for example, I had a user email me lately who included an "@" and an "&" in his password, and he wasn't able to connect because the symbols weren't getting parsed properly for the url). Is there any way around sending the credentials in the url so that I can allow users to use something other than just alphanumeric in their passwords?

    var username = cookie.get().servers[this.serverIndex].username;
    var password = cookie.get().servers[this.serverIndex].password;
    this.auth = 'Basic ' + Base64.encode(username + ':' + password);
    var baseUrl = 'http://' + url + ':' + port + '/gui/';
    this.baseUrl = baseUrl;


    var request = new Ajax.Request(this.tokenUrl, {
        method: 'get',
        timeout: 2000,
        headers: {
            Authorization: this.auth
        },
        onSuccess: successFunc,
        onFailure: this.failure.bind(this)
    });

Response is (I removed the url for security reasons):

{"request": {"options": {"method": "get", "asynchronous": true, "contentType": "application/x-www-form-urlencoded", "encoding": "UTF-8", "parameters": {}, "evalJSON": true, "evalJS": true, "timeout": 2000, "headers": {"Authorization": "Basic c3VubW9yZ3VzOmZyb2dneUAlMjY="}}, "transport": {"readyState": 4, "onloadstart": null, "withCredentials": false, "onerror": null, "onabort": null, "status": 401, "responseXML": null, "onload": null, "onprogress": null, "upload": {"onloadstart": null, "onabort": null, "onerror": null, "onload": null, "onprogress": null}, "statusText": "", "responseText": "", "UNSENT": 0, "OPENED": 1, "HEADERS_RECEIVED": 2, "LOADING": 3, "DONE": 4}, "url": ""

解决方案

Send the Basic authentication info with header: http://coderseye.com/2007/how-to-do-http-basic-auth-in-ajax.html

var auth = 'Basic ' + Base64.encode(user + ':' + pass);
Ext.Ajax.request({
    url : url,
    method : 'GET',
    headers : { Authorization : auth }
});

这篇关于使用验证用的Ajax.Request的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆