簡體   English   中英

如何在Zapier代碼中提供基本的HTTP身份驗證?

[英]How to provide basic HTTP authentication in Zapier code?

文檔提供了有關訪存API的簡單示例:

fetch('http://example.com/')
  .then(function(res) {
    return res.text();
  })
  .then(function(body) {
    var output = {id: 1234, rawHTML: body};
    callback(null, output);
  })
  .catch(callback);

查詢數據。

如何在這些結構中添加標題或傳遞帖子數據?

一個可以使用標准的Fetch API可能性(第二個參數是請求的選項,您可以在其中傳遞標頭,要使用的HTTP方法等),例如

var myInit = { method: 'GET',
               headers: {
                authentication: 'Basic lkjbwkejbf...'
               },
               mode: 'cors',
               cache: 'default' };

fetch('flowers.jpg', myInit).then(function(response) {
  return response.blob();
}).then(function(myBlob) {
  var objectURL = URL.createObjectURL(myBlob);
  myImage.src = objectURL;
});

就像這里描述的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM