ES6获取错误400 - 无效请求

时间:2018-04-18 16:56:23

标签: javascript json ecmascript-6 fetch

我正在开发一个调用外部REST服务的reactjs应用程序。问题是fetch返回" 400无效请求"好像身体无效,但它不是。

const sub=(store,rulesMap,values) =>{
  const buffer=packer.pack(rulesMap,values);
  const body=prepareBody(buffer,rulesMap);
  fetch('http://STMIVAPIGTW01.si.it:8080/ip-engine/pay',
    {
        mode:'no-cors',
        headers: {
            'Accept': 'application/json, text/plain, */*',
            'Content-Type': 'application/json'
        },
        method:'POST',
        body: JSON.stringify(body),
    })
    .then(function(response) {
        console.log(response);
        if (response.ok)
            return response.json();
        else
            return response.text();
    })
    .catch(error => window.alert('Error:'+ error))
    .then(function(myJson) {
        window.alert(myJson);
    });
}

我不能张贴身体因为太长但身体得到了邮递员的正确答案。 这是我第一次使用fetch。有什么建议吗? 感谢

0 个答案:

没有答案