Fetch API yields quot;TypeError: failed to fetchquot;(Fetch API 产生“TypeError: failed to fetch)
问题描述
我在 Chrome 上,看到这个奇怪的错误:
I am on Chrome, and I see this bizarre error:
TypeError: failed to fetch
(是的,这就是整个错误消息).
这是产生错误的代码:
fetch(logoUrl, {
    method: 'put',
    headers: {
      'Content-Type': 'image/jpeg',
      //encode credentials as base64
      'Authorization': 'Basic ' + btoa('cdt-deployer:xyz'),
    },
    body: imgFile // the file
  }).catch(function(err){
       // the error appears here
  })
我该怎么办?我不知道出了什么问题.我只是想将二进制图像文件发送到另一台服务器(我看不到服务器日志).
what am I supposed to do? I have no idea what's wrong. I am simply trying to send a binary image file to another server (I cannot see the server logs).
推荐答案
来自 获取 API 文档:
当遇到网络错误时,fetch() 承诺会以 TypeError 拒绝,尽管这通常意味着权限问题或类似问题.
A
fetch()promise rejects with aTypeErrorwhen a network error is encountered, although this usually means a permissions issue or similar.
其中一个可能是网络错误"的可能原因:
One of these may be possible causes of "network error":
- DNS 问题
 logoUrl处的服务器不可用/错误- 错误的 HTTP 标头导致服务器忽略请求
 - 浏览器中止 - 很可能是由于在获取完成之前导航到另一个页面
 
- DNS problems
 - the server at 
logoUrlis unavailable / erroneous - Erroneous HTTP Headers causing server to ignore the request
 - Browser aborted -- most likely due to navigation to another page before the fetch completes
 
这篇关于Fetch API 产生“TypeError: failed to fetch"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Fetch API 产生“TypeError: failed to fetch"
				
        
 
            
        - Flexslider 箭头未正确显示 2022-01-01
 - addEventListener 在 IE 11 中不起作用 2022-01-01
 - Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
 - Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
 - CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
 - 400或500级别的HTTP响应 2022-01-01
 - 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
 - 失败的 Canvas 360 jquery 插件 2022-01-01
 - Fetch API 如何获取响应体? 2022-01-01
 - 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
 
						
						
						
						
						