fetch patch request is not allowed

后端 未结 3 1332
萌比男神i
萌比男神i 2020-12-14 06:26

I have two apps one is a react front end and the second one is the rails-api app.

I have been happily using isomorphic-fetch till I needed to send PATCH method to th

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 06:52

    I had this error while PATCH was all caps. I was also getting this error with DELETE and PUT too. I checked the headers of my fetch and I saw a OPTIONS method. I was using the isomorphic-fetch lib here - https://www.npmjs.com/package/isomorphic-fetch

    The fix for me was to add to my PHP page:

    Without this, in Firefox 53 I would keep getting the javascript error:

    NetworkError when attempting to fetch resource.

    The fetch I was doing was this:

    try {
        await fetch('https://my.site.com/', {
            method: 'PATCH',
            headers: { 'Content-Type':'application/x-www-form-urlencoded' },
            body: 'id=12&day=1'
        });
    } catch(ex) {
        console.error('ex:', ex);
    }
    

提交回复
热议问题