Fetch: post json data, application/json change to text/plain

前端 未结 3 1091
忘了有多久
忘了有多久 2020-12-14 02:45

I\'m using chrome 53.0.2785.116 m (64-bit).

I got the following headers on devtools. The problem is marked with a \"//\" comment. content type is really not allowing

3条回答
  •  囚心锁ツ
    2020-12-14 03:10

    Thanks a lot! More than 6 hours to solve this.

    In my nodejs server

    npm install --save cors
    

    at app.js I inserted the lines:

    var cors = require('cors');
    var app = express(); 
    app.use(cors());
    

    and in my react client:

    var shape_for_db = JSON.stringify(layer.geometry);
    const trechoRede = {
        method: "POST",
        mode: "cors",
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
             body: shape_for_db
    };
    

提交回复
热议问题