FineUploader-在标头中添加身份验证 [英] FineUploader - add authentication in header
问题描述
我在跨域上传项目中使用FineUploader 3.7.一切正常,直到我将代码移至具有简单身份验证的客户端DEV服务器.在将预检请求发送到服务器时,是否可以将身份验证信息嵌入表单中?
I'm using FineUploader 3.7 in cross domain uploading project. Everything is fine until I move the code to client's DEV server which has simple authentication. Is there a way to embed authentication information in the form when the preflight request is sent to the server?
我尝试在标头中嵌入基本身份验证,但是不起作用.请参考下面的代码:
I have tried to embed basic auth in headers, however not working. Please refer to the code below:
$.ajaxSetup({
headers: {
'Authorization': "Basic YZVjaGFmbWluOkNieWxjBTY3"
},
beforeSend: function (jqXHR, settings) {
jqXHR.setRequestHeader('Authorization', 'Basic YZVjaGFmbWluOkNieWxjBTY3');
}
});
还有,我尝试设置自定义标头,但没有运气:
And even more, I have tried to set the custom header and no luck:
var manualuploader = new qq.FineUploader({
customHeaders: {
'Authorization': 'Basic YXVjaGFkbWluOkNieWxjZTY3'
},....
推荐答案
您的customHeaders
选项未正确定义. customHeaders
是request
选项的属性,如
Your customHeaders
option isn't defined properly. customHeaders
is a property of the request
option, as detailed in the request
option documentation.
您的Fine Uploader集成代码应如下所示:
Your Fine Uploader integration code should look like this instead:
var manualuploader = new qq.FineUploader({
request: {
endpoint: "path/to/your/server",
customHeaders: {
"Authorization": "Basic YXVjaGFkbWluOkNieWxjZTY3"
}
}
});
此外,请记住,jQuery的ajaxSetup
对Fine Uploader的ajax/xhr调用没有影响. Fine Uploader内部完全不使用jQuery. Fine Uploader提供的可选jQuery插件只是包装了本机javascript库,从而通过支持与jQuery和jQuery插件相关的通用语法,可以轻松地将其用作jQuery插件.
Also, please keep in mind that jQuery's ajaxSetup
has no effect on Fine Uploader's ajax/xhr calls. Fine Uploader does not use jQuery at all internally. The optional jQuery plug-in offered by Fine Uploader simply wraps the native javascript library to allow it to be easily used as a jQuery plug-in by supporting syntax common associated with jQuery and jQuery plug-ins.
此外,请注意,在IE9及更高版本中,这些标头将不会随上传请求一起传递,因为IE9及更高版本不支持通过ajax/xhr进行上传.在这些浏览器中,提交了一个以iframe为目标的表单.如果是表单提交,则无法将自定义标题与请求相关联.
Also, please be aware that these headers will not be passed along with the upload request in IE9 and older, since IE9 and older do not support uploads via ajax/xhr. In those browsers, a form, targeting an iframe, is submitted. In the case of a form submit, there is no way to associate custom headers with the request.
这篇关于FineUploader-在标头中添加身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!