Mailchimp api无法与fetch和Reactjs一起使用

问题描述 投票:0回答:1

我无法使获取api与React中的mailchimp api一起使用。我也在使用webpack运行devserver。

这是我所拥有的:

componentDidMount() {
    let authenticationString = btoa('123:myapikey-us17');
    authenticationString = "Basic " + authenticationString;

    fetch('https://us17.api.mailchimp.com/3.0/lists/fakelistid/segments', {
      mode: 'no-cors',
      method: 'GET',
      credentials: 'same-origin',
      headers: new Headers({
        'Authorization': authenticationString,
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      })
    }).then(function(e){
      console.log("fetch finished")
    }).catch(function(e){
      console.log("fetch error");
    })
  }

我已经在Postman中测试了完全相同的api请求,并且工作正常。

当我在React中尝试此操作时,我一直收到401状态代码,上面写着“您的请求未包含API密钥。”

reactjs mailchimp fetch-api
1个回答
0
投票

这是因为您使用的是GET请求而不是POST请求。

© www.soinside.com 2019 - 2024. All rights reserved.