Reactjs 已解决请求承诺错误:“;TypeError:无法获取“文件”;即使请求没有';不要在React.js中失败

Reactjs 已解决请求承诺错误:“;TypeError:无法获取“文件”;即使请求没有';不要在React.js中失败,reactjs,request,cors,request-promise,Reactjs,Request,Cors,Request Promise,我正在尝试在React.js应用程序中获取API。但是,即使请求成功,我的React应用程序仍返回一个错误“TypeError:failed to fetch”。这是我的密码: function shorten(longlink) { const apikey = "**********"; const protocol = "http"; let data; const submitlink = `https://cutt.ly/api

我正在尝试在React.js应用程序中获取API。但是,即使请求成功,我的React应用程序仍返回一个错误“TypeError:failed to fetch”。这是我的密码:

function shorten(longlink) {
  const apikey = "**********";
  const protocol = "http";
  let data;

  const submitlink = `https://cutt.ly/api/api.php?key=${apikey}&short=${protocol}://${longlink}`;

  rp(submitlink).then(body => {
    data = JSON.parse(body);
  })

  console.log(data);
  }
我想这是因为我从本地服务器发送了一个请求-http://localhost:3000. 我也试着用标题“no cors”来取回,但对我来说不起作用。这里还有来自控制台的错误:

Access to fetch at 'https://cutt.ly/api/api.php?key=**********&short=http://dawidszarek.me' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

如何修复它?

邮递员那里试试你的服务。
有效吗?对邮递员有效。
https://cutt.ly/api/api.php
显然未启用CORS
CORS
设置与
后端相关