我正在尝试使用localhost中的fetch方法发布帖子

时间:2018-03-04 18:08:37

标签: javascript ajax cors fetch

我尝试使用带有头文件身份验证的提取来从localhost发布一个对象 (python -m SimpleHTTPServer)。

proxyurl:CORS Anywhere是一个代理,它将CORS标头添加到代理请求

    var proxyurl = "https://cors-anywhere.herokuapp.com/";
    //Public Development Server
    url  = 'https://public.coindaddy.io:14001/api/',
    auth = 'rpc:1234';

    var settings = {
      "crossDomain": false,
      "method": "POST",
      timeout: 60000,    // timeout after 60 seconds of waiting
      "headers": {
        "authorization": "Basic " + auth,
        "Content-Type": 'application/json; charset=UTF-8',
      }

    fetch(proxyurl+url,settings ).then(response => console.log('Success:', response));
    }

请求总是因HTTP状态401而失败   任何解决方案?

Exemple on jsfiddle

0 个答案:

没有答案