GithubHelp home page GithubHelp logo

Comments (13)

14113 avatar 14113 commented on June 9, 2024 17

There is some wired think. When I remove line with:

 'Content-Type': 'application/json'

it works.

So this is correct setup:

import fetch from 'isomorphic-fetch'

fetch('http://localhost:3000/api/v1/sign_in', {
    method: 'POST',
    headers: {
      'Accept': 'application/json'
    },
    body: {
      login: 'test'
    }
})

No OPTIONS request anymore.

from isomorphic-fetch.

jmwohl avatar jmwohl commented on June 9, 2024 12

Removing the 'Content-Type': 'application/json' works... does anyone know why? Is it a bug, or is this expected?

from isomorphic-fetch.

borm avatar borm commented on June 9, 2024 7

Not worked for me, and method options is random

fetch('URL', {
  headers: {'Token': ...},
  method: 'POST',
  body: JSON.stringify({....})
})

from isomorphic-fetch.

max107 avatar max107 commented on June 9, 2024 5

OPTIONS is a crossorigin. https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

from isomorphic-fetch.

JohnBaileyN avatar JohnBaileyN commented on June 9, 2024

I think this Issue can be closed. This is how Browsers behave as @max107 pointed out.

from isomorphic-fetch.

zlwaterfield avatar zlwaterfield commented on June 9, 2024

@14113 That worked for me, thanks.

from isomorphic-fetch.

AienTech avatar AienTech commented on June 9, 2024

Also got this issue, but removing content-type won't help!

from isomorphic-fetch.

zeng-ge avatar zeng-ge commented on June 9, 2024

sometimes, remove content-type caused modify server-end codes

from isomorphic-fetch.

AlexRogersJG avatar AlexRogersJG commented on June 9, 2024

@borm How do you mean random? You're getting OPTIONS because you have a custom header Token by the looks of it

from isomorphic-fetch.

thomi137 avatar thomi137 commented on June 9, 2024

Does not work here either. Despite the fact I set the header to content-type: application/json, when fetching, this somehow gets changed to text... And my webservice will complain. Back to axios then...

from isomorphic-fetch.

thecodegoddess avatar thecodegoddess commented on June 9, 2024

We are having the same issue as well. We have to have the content-type header, so this lib won't work for us

from isomorphic-fetch.

quickshiftin avatar quickshiftin commented on June 9, 2024

I can confirm this is working properly even with the Content-Type header. In my case I need to send a cross-origin PUT request with a JSON payload. In this case, a pre-flight request issued by the browser is expected as @max107 said early on in this thread. Here's my request invocation with isomorphic-fetch:

import fetch from 'isomorphic-fetch';
const productId = 1;
const data = {description: 'An updated product description!'};
const res = await fetch(
    `https://my-api.com/product/${productId}`,
    {
        method: 'PUT',
        body: JSON.stringify(data),
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
        },
    });
const data = await res.json();

After implementing support for CORS requests on my server, I was still getting tripped up for a bit because the Chrome network tab was only listing the OPTIONS request, however my Apache logs showed two requests, OPTIONS followed by PUT as expected...

I was about to file a bug with Chrome, however, I realized that after unchecking the XHR filter in the network tab, my PUT request became visible. Feels like a Chromism (read: bug)... Seems the PUT request does not count as XHR in the network tab's eyes, despite the fact all the GET requests I've sent through this library do, LOL. (Maybe something funky with the pre-flight flow inside the browser).

Still though, FWIW, isomorphic-fetch is working as expected in this regard AFAICT.

from isomorphic-fetch.

kellyrmilligan avatar kellyrmilligan commented on June 9, 2024

removing content type worked for me, but i'm also going to investigate setting up the cors headers properly. ATM just setting it in apache to test.

from isomorphic-fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.