2016-12-28 30 views

回答

1

只需設置取方法爲「POST」,加在頭和身體作爲鍵 - 值對和處理響應。這是一個例子。

var bodyMap = {}; 
// fill in the body map with keyvalue pair 
fetch(POST_URL, { 
     method: 'POST', 
     headers: { 
      'Accept': 'application/json', 
      'Authorization': authValue, 
      'Content-Type': 'application/json', 
     }, 
     body: JSON.stringify(bodyMap) 
     }).then((response) => response.json()) 
     .then((responseData) => { 
      console.log(responseData); 
      //process response 
     }) 
     .catch((error) => { 
      console.warn(error); 
     }); 
+0

感謝Irfan Ayaz。 能否請你解釋一下,如何讓「authValue」與用戶名和密碼從片段? – krish2me

+0

這取決於服務器如何期待它。在基地64 –

+0

服務器期望授權值?看起來你不夠清楚。什麼鍵值對服務器期待用戶名和密碼?您不能僅使用base64生成authvalue。如果您可以從服務器獲取所需的信息,我可以幫助您。 – krish2me