Javascript 407 需要代理认证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2808590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
407 Proxy Authentication Required
提问by 0cool
I'm getting the following exception while making a call using XMLHttp object asynchronously in Mozilla Firefox.
在 Mozilla Firefox 中异步使用 XMLHttp 对象进行调用时出现以下异常。
407 Proxy Authentication Required
The ISA Server requires authorization to fulfill the request.
Access to the Web Proxy filter is denied.
Description of cause:
原因描述:
Actually I'm trying to make an asynchronous request to using get in javascript. It is working fine using IE 6 but for IE 7 and Firefox 3.5, it will it won't get any data using asynchronous request so how to overcome this problem?
实际上,我正在尝试向在 javascript 中使用 get 发出异步请求。它使用 IE 6 工作正常,但对于 IE 7 和 Firefox 3.5,它不会使用异步请求获取任何数据,那么如何克服这个问题?
When I debug in Firefox 3.5 using firebug it shows
当我使用 firebug 在 Firefox 3.5 中调试时,它显示
407 Proxy Authentication Required The ISA Server requires authorization to fulfil the request. Access to the Web Proxy filter is denied.
exception at console so how to tackle this issue
控制台异常,如何解决这个问题
Note: our network has proxy server
注意:我们的网络有代理服务器
回答by sdolgy
I recognize I am a little late to the party here, and this question, however, I was having the exact same problem. @FK82 indicated the right solution and I wanted to document it, as I've tried it and it works.
我知道我参加聚会有点晚了,但是这个问题,我遇到了完全相同的问题。@FK82 指出了正确的解决方案,我想记录它,因为我已经尝试过并且它有效。
$.ajax({
url: "http://somefancyurl.com/api/do_it",
data: { id:"user" },
dataType: "jsonp",
success: function(data) {
console.log(data);
}
});
If I do not specify jsonpI get the 407 Proxy Authentication Requirederror.
如果我不指定 jsonp,我会收到407 Proxy Authentication Required错误。
- Although the original question didn't specify JQuery, I was able to test successfully with FireFox 3.6.x, and IE7 using this approach & JSONP.
- 虽然最初的问题没有指定 JQuery,但我能够使用这种方法和 JSONP 在 FireFox 3.6.x 和 IE7 上成功测试。
回答by YOU
Proxy Authentication is simply an existence of a http header field called "Proxy-Authorization"
代理身份验证只是存在一个名为的 http 标头字段 "Proxy-Authorization"
Browsers are supposed to send those stuff automatically.
浏览器应该自动发送这些东西。
But since you could add some custom header to ajax requests, you could try setting it manually.
但是由于您可以向 ajax 请求添加一些自定义标头,您可以尝试手动设置它。
request.setRequestHeader("Proxy-Authorization", value);
- requestis the XMLHttp object
- valueis the base64 encoded version of
username:password
- request是 XMLHttp 对象
- 值是 base64 编码的版本
username:password
Note that I am not sure thats the case or not, correct me if I am wrong.
请注意,我不确定是不是这样,如果我错了,请纠正我。
Or some page I found on google says to add X-Requested-With, may be worth to try that too.
或者我在谷歌上找到的某个页面说要添加X-Requested-With,也可能值得一试。
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");

