How to make a rest post call from ReactJS code?

前端 未结 9 1956
一生所求
一生所求 2020-12-02 05:28

I am new to ReactJS and UI and I wanted to know how to make a simple REST based POST call from ReactJS code.

If there is any example present it would be really h

9条回答
  •  无人及你
    2020-12-02 06:13

    you can install superagent

    npm install superagent --save
    

    then for make post call to server

    import request from "../../node_modules/superagent/superagent";
    
    request
    .post('http://localhost/userLogin')
    .set('Content-Type', 'application/x-www-form-urlencoded')
    .send({ username: "username", password: "password" })
    .end(function(err, res){
    console.log(res.text);
    });  
    

提交回复
热议问题