Failing fetch request with ofx body

时间:2018-04-18 18:02:02

标签: javascript ajax reactjs fetch

Probably Im missing something trying to run fetch request in react app with XML OFX body, the POSTMAN request is passing successfully but fetch returning 404. example:

    const body = '<?xml version="1.0" encoding="UTF-8"?><OFX><SIGNONMSGSRQV1>...some body </SIGNUPMSGSRQV1></OFX>';
    const url = '10.10.10.110'// fake address
     fetch(url, {
      method: "POST",
      mode: 'cors',
      body: body,
      headers: {
          'Content-Type': 'application/x-ofx'
      }
    }).then((res)=>{
      console.log(res.status);
    }).catch((err) => {
      console.log('Err', err);
    })
 

the body: JSON.stringify(body) giving the same 404;

1 个答案:

答案 0 :(得分:0)

找出使用fetch发送该请求的方法 问题ID标题。 你不能在标题中发送ofx

const body = `<OFX>...request body...</OFX>`;
    const url = 'http://requestserver';
     return fetch(url, {
      method: "POST",
      body: body,
      mode: 'cors',
      headers: {
          'Content-Type': 'text/plain;charset=UTF-8"'
      }