2017-08-29 55 views
0

文檔提供了與取API簡單的例子:如何在Zapier代碼中提供基本的HTTP身份驗證?

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

查詢數據。

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

+0

[在zappier代碼基本HTTP認證]的可能的複製(https://stackoverflow.com/questions/45934030/basic-http-auth-in-zappier-code) – malditojavi

回答

0

可以使用標準的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; 
}); 

等中描述here