Comments (13)
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.
Removing the 'Content-Type': 'application/json'
works... does anyone know why? Is it a bug, or is this expected?
from isomorphic-fetch.
Not worked for me, and method options is random
fetch('URL', {
headers: {'Token': ...},
method: 'POST',
body: JSON.stringify({....})
})
from isomorphic-fetch.
OPTIONS is a crossorigin. https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
from isomorphic-fetch.
I think this Issue can be closed. This is how Browsers behave as @max107 pointed out.
from isomorphic-fetch.
@14113 That worked for me, thanks.
from isomorphic-fetch.
Also got this issue, but removing content-type won't help!
from isomorphic-fetch.
sometimes, remove content-type caused modify server-end codes
from isomorphic-fetch.
@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.
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.
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.
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.
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)
- Upgrade node-fetch to >= 2.3.0 to fix semantic-release users that use styled-components HOT 2
- Fix version of whatwg-fetch HOT 1
- eiddccgeilvtdejdrvblujinlecirnvcbbnnnunegklr
- AbortController not working with this library HOT 4
- URLSearchParams in body doesn't set content-type to x-www-form-urlencoded
- Is this library still been maintained? HOT 4
- Tag a new version with the security fix HOT 11
- Add v3.0.0 release notes HOT 2
- How to handle error messages from server - Question HOT 1
- Node.js - realFetch.call is not a function HOT 8
- Isomorphic-fetch Typescript setup HOT 2
- Upgrade node-fetch to version 2.6.1 or 3.0.0-beta.9 HOT 1
- fetch api
- update node-fetch to v3.x HOT 7
- Security risk
- Found a possible security concern HOT 2
- Interceptors
- How to access the referer using isomorphic fetch library? An example would help!
- Dual Form
- Isomorphic fetch returns response with empty stream body HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from isomorphic-fetch.