我目前有一个 Palm WebOS 应用程序,它使用 Ajax.Request 连接到使用基本身份验证的 Web 服务。要发送用户名和密码,我只需将其包含在 url 中(即http://username:password@ip-address:port/),它工作得非常好,期望密码包含除字母数字字符以外的任何内容(例如,我最近有一个用户给我发了电子邮件,他的密码中包含一个“@”和一个“&”,他无法连接,因为这些符号没有被正确解析为 url)。有什么办法可以在 url 中发送凭据,以便我可以允许用户在密码中使用除字母数字以外的其他内容?
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)
});
响应是(出于安全原因,我删除了网址):
{"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": ""