Currently, dva 2.2.3 proxy will block post requests

this problem is the same as that mentioned in tutorial )

clone https://github.com/umijs/umi-.

its .webpackrc.js is as follows

export default {
    "proxy": {
        "/api": {
          "target": "http://jsonplaceholder.typicode.com/",
          "changeOrigin": true,
          "pathRewrite": { "^/api" : "" }
        }
      },
}

http://jsonplaceholder.typico. is a test platform
/ user GET method can return some mock user
/ user POST body: {" id ": 22," name ":" test "}, it will return {" id ": 22," name ":" test "}

. The address of the front-end project after

npm start is http://localhost:8000, according to the proxy, set in webpack. When we visit http://localhost:800/api/users, webpack"s devServer will help us proxy to http://jsonplaceholder.typicode.com/users

.

after the above proxy is set:
GET http://localhost:8000/api/users is normal
POST http://localhost:8000/api/users with body data will be blocked by proxy server, as shown in indeed to request http://jsonplaceholder.typicode.com,, but body will not be sent, but will be blocked . I added the "host" field to header according to the solution mentioned in issue above, but it didn"t work.

Please have a look at it, otherwise I can only set cross-domain settings on my own backend server, and then all url developed will have cross-domain settings.

Mar.28,2021

has it been solved? Brother, I cannot receive parameters when dva post requests backend


if the get method can get the parameters of url , but the post request cannot get the parameters of body , it is very likely that there is something wrong with the writing of the backend interface.
if you are using springmvc, you can annotate the parameter @ RequestBody , and that's fine.

Menu