Aurelia使用HEAD方法获取客户端
我对Aurelia中的fetch(http)客户端有一个简单的要求:使用“head”方法向url发出http请求,以确定资源是否存在(但不下载它) 打电话很容易:Aurelia使用HEAD方法获取客户端,aurelia,fetch-api,Aurelia,Fetch Api,我对Aurelia中的fetch(http)客户端有一个简单的要求:使用“head”方法向url发出http请求,以确定资源是否存在(但不下载它) 打电话很容易: this.http.fetch('http://the.url/something.jpg', { method: 'head', mode: 'no-cors' }) .then(response => { this.urlIsValid = response.status === 200; }) .catch
this.http.fetch('http://the.url/something.jpg', { method: 'head', mode: 'no-cors' })
.then(response => { this.urlIsValid = response.status === 200; })
.catch(error => { ... Handle error });
但是,fetch客户端似乎从未进入.then()方法,它总是被.catch()捕获
更新:根据请求,其中一个请求的标题(由Chrome捕获)为空 Url存在:
Request URL:https://xxx/the/url.pdf
Request Method:HEAD
Status Code:200 OK
Remote Address:xx.xx.xx.xx:443
Accept-Ranges:bytes
Connection:keep-alive
Content-Length:278188
Content-Type:application/pdf
Date:Mon, 08 Feb 2016 00:12:21 GMT
ETag:"955492e4afe7b2199e15cfafd747df27"
Last-Modified:Sun, 13 Dec 2015 01:20:37 GMT
Server:AmazonS3
Via:1.1 xxxxxxx.cloudfront.net (CloudFront)
X-Amz-Cf-Id:g7dK2pGwdnrKAZnkKOvjm0LUyb78dVdiZLB26x-mGbzI8bc9oUa75Q==
X-Cache:Miss from cloudfront
403:
你的回答不是空白的,而是空白的。不透明响应无法读取,并且是使用
模式请求的结果:“无cors”
。您需要设置模式模式:“cors”
以允许访问您的响应,但是,服务器在回答HEAD请求时应设置正确的模式。您可以使用类似的方式访问资源吗?如果可以的话,F12开发者工具是否提供了任何其他信息?我承认,no-cors位可能会导致问题,但是提供了http状态值(200、405等),并且肯定可以访问!?这是您的then()
处理程序的真实代码吗?如果then()
处理程序中存在表达式,则可能是调用了catch。不透明响应的状态代码为0。
Request URL:https://xxx/invalid/file.pdf
Request Method:HEAD
Status Code:403 Forbidden
Remote Address:xx.xx.xx.xx:443
Connection:keep-alive
Content-Type:application/xml
Date:Mon, 08 Feb 2016 00:16:12 GMT
Server:AmazonS3
Via:1.1 xxxxxx.cloudfront.net (CloudFront)
X-Amz-Cf-Id:q1id8NggywGeBF8PrQuU5L5a--EKGLM7x2glBke-rvV45lXV7Ch2Vg==
X-Cache:Error from cloudfront