且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JQuery的Ajax和HTTP基本认证要求

更新时间:2022-06-13 06:02:44

此问题可能是早已过了有效期,但我正在用同样的事jQuery和遇到了同样的问题。

This question is probably well past its' expiry date, but I was working with the same thing with Jquery and came across the same problem.

似乎用户名和密码属性不会做一个base64连接$ C $的用户名/密码了C为你做正常完成HTTP基本身份验证。

The username and password attributes do not seem to do a base64 encode of the username/password as you do to normally accomplish HTTP basic auth.

请看下面的请求(简称为简洁起见),先使用用户名和密码参数中的JQuery的AJAX方法:

Look at the following requests (shortened for brevity), firstly using the "username" and "password" parameters in the JQuery AJAX method:

Request URL:http://testuser%40omnisoft.com:testuser@localhost:60023/Account
Request Method:GET
Accept:application/json, text/javascript, */*; q=0.01
Host:localhost:60023

现在用beforeSend方法:

And now with the beforeSend method:

Request URL:http://localhost:60023/Account
Request Method:GET
Accept:application/json, text/javascript, */*; q=0.01
Authorization:Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Host:localhost:60023

请注意,第一个方法不包括在请求中的授权头,而是prefixes目标URL。我在HTTP基本身份验证方面的专家,但它表明,前者不是一个正确执行,因此失败(或至少它与我自己的服务器实现)。

Note that the first method does not include an 'Authorization' header in the request, but instead prefixes the target URL. I'm no expert on HTTP basic auth, but it would indicate that the former is not a proper implementation and therefore fails (or at least it does with my own server implementation).

至于你的选择要求使用JSONP - ?你可能尝试使用回调= 在您的网址,而不是使用跨域选项,仅仅是明确的。

As to your OPTIONS request using JSONP - you could possibly try using ?callback=? in your URL instead of using the crossdomain option, just to be explicit.