- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从需要基本身份验证的服务器获得一些响应。所以当我使用 curl 时:
curl -u user:pass http://myserver.com/get/send-my-data
$.ajax ({
type: 'GET',
url: 'http://myserver.com/get/send-my-data',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic" + encode64(user:pass)); // I have calculated base64 encoded value of user:pass correctly.
},
success: function(d) { console.log(d); },
crossDomain: 'true'
});
> POST /get/send-my-data HTTP/1.1
**> Authorization: Basic ********** // Removed original code deliberately**
> User-Agent: curl/7.27.0
> Host: localhost:8080
> Accept: */*
> Content-Length: 264
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------3c0e06f1e2b4
OPTIONS /get/send-my-data HTTP/1.1
Host 10.40.55.110:4502
Access-Control-Request-Method GET
Origin http://localhost:8080
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
**Access-Control-Request-Headers origin, authorization, accept**
Accept */*
Referer http://localhost:8080/proof/check.html
Accept-Encoding gzip,deflate,sdch
Accept-Language en-US,en;q=0.8
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.3
最佳答案
我面临这个问题是因为我正在发送一个跨域请求并且请求使用了 POST 方法。所以当我们在跨域服务器上进行POST时,就有了的概念。预检 这是图片。
在 Preflight 中,它只发送选项 header 并告诉资源将要命中哪个请求。然后服务器决定发送请求是否安全。
然后如果服务器发送 OK,则发送实际请求。
可能这些行会更具解释性。
Preflighted requests first send an HTTP request by the OPTIONS method to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a request is preflighted if:
It uses methods other than GET, HEAD or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML payload to the server using application/xml or text/xml, then the request is preflighted.
It sets custom headers in the request (e.g. the request uses a header such as X-PINGOTHER)
关于authentication - 使用 XHR 的基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12852534/
这可能是一个非常明显的问题,但请解释一下 xhr 和 xhr.upload 之间的区别是什么? 我的用例是我正在将文件上传到服务器,但假设服务器出现故障。在这种情况下,我应该处理 xhr.onerro
这是我的场景: 我有一个 URL,可以生成管理工作区的大量导出 - 它通常约为 3mb,需要约 15 秒才能生成。 当前的实现是对按钮上带有 download 属性的 URL 的正常同步请求,以强制下
我正在执行 XMLHttpRequest,如果失败,我想回退到执行其他操作(读取本地文件),但我想在 XHR 函数 (getDBfileXHR) 本身之外执行此操作。 我也在使用 Jquery。 考虑
XMLHttpRequest 实例上有五个事件。 var xhr = new XMLHttpRequest(); xhr.onloadstart = res => { console.log(
xhr.open('put',url,false) xhr.upload.addEventListener('load',function(e){alert(xhr.responseText)},fa
我正在尝试 promisify the native XHR , 现在问题来了,当我使用下面的代码时: function request(method, url) { return new P
我想知道.. 我怎样才能得到 XHR finished loading 字符串? 基本上,我在 Google instant 的页面上,我想以字符串的形式返回搜索结果的“真实”URL。 最佳答案 如果
是否可以在 XMLHttpRequest 的 onreadystatechange 处理程序中找到作为参数发送到 XMLHttpRequest 的 send(data) 函数的数据?我认为此时它必须存
当我在 xhr.then() 中返回“结果”并且我使用 dojo 1.10.4 时遇到一些问题,请帮助我! 以下代码在dojo中使用xhr('dojo/request/xhr')连接到API: rem
这个问题在这里已经有了答案: How to structure nested Promises (3 个答案) 关闭 6 年前。 我需要做一个 promise 序列。我想使用基于标准的方法(ES6?
当执行“GET”请求时,xhr.response 和 xhr.responseText 都返回相同的值。有什么不同?有吗? 最佳答案 response 被解释为 ArrayBuffer、Blob、Do
我只需要支持主要的现代浏览器(IE10+、FF、Chrome、Safari) 我可以做这个替换吗,因为我想简化我的代码库: 来自: xhr.onreadystatechange = function
DataTables 版本:1.10.20 我目前正在使用 pipeline plugin并聆听 xhr event 。 xhr 事件按预期触发,但是回调中的 xhr 参数未定义。设置对象中还有一个
在非常高的级别上,我们单击一个命令建筑物控制点的按钮;打开或关闭灯。单击应该向服务器发送 POST 请求。问题是有时单击按钮但 POST 请求不会发出。该按钮没有指示它是否已被单击的功能(小幅增强)。
我正在尝试使用 youtube v3 API 上传视频,查看 this示例。 所以,我写了这样的东西: var xhr = new XMLHttpRequest(); xhr.open('PUT',
我正在使用 XHR GET 获取 Blade html 并尝试缓存它,这样它就不需要每次都去服务器下载它。这是我的代码。 但这不起作用并且总是转到服务器。 $.ajax({ method: "
我正在尝试为文件上传创建一个进度条,但由于某种原因,XHR 进度响应仅在最后触发一次。但是,如果我打开 firebug 窗口,它可以 100% 正常工作(在文件上传过程中触发)。我正在本地主机上测试它
我正在尝试获取 xhr 请求。 (该脚本应每 2 秒循环运行一次)这是我的脚本: function getJson() { var xhr = new XMLHttpReque
我有一个简单的 XHR 来加载“testdirectory/testpage.html” var xhr; (XMLHttpRequest) ? xhr= new XMLHttpRequest() :
我正在使用XHR npm 上的 lib 用于在 JS 应用程序的客户端发出 ajax 请求。我的代码如下所示: xhr({uri: "http://foo"},function (err, resp,
我是一名优秀的程序员,十分优秀!