2017-07-28 41 views
0

我在Chrome和我看到這個奇怪的錯誤:提取API收益「類型錯誤:無法取得」

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 
    }) 

那我該怎麼辦?我不知道什麼是錯的。我只是試圖發送一個二進制映像文件到另一臺服務器(我看不到服務器日誌)。

+0

請發佈完整的錯誤。 – emil

+0

如果您嘗試使用其他瀏覽器,您是否會遇到同樣的錯誤?你是否已經使用curl或Postman等其他客戶端成功完成了PUT? – sideshowbarker

+0

@emil是完全錯誤的傢伙。我在這個問題中說過。 –

回答

1

Fetch API documentation

A fetch() promise rejects with a TypeError when a network error is encountered, although this usually means a permissions issue or similar.

其中的一個可以是 「網絡錯誤」 的可能的原因:

  • DNS問題
  • logoUrl服務器不可用/錯誤
  • 導致服務器忽略請求的錯誤HTTP標頭
  • 瀏覽器中止 - 最有可能是由於導航到另一個頁面取得完成之前
相關問題