SoFunction
Updated on 2025-04-05

vue post application/x-www-form-urlencoded How to implement parameter transfer

vue post application/x-www-form-urlencoded parameter

When using axios for parameter acquisition, it is always impossible to obtain, but calling postman is normal, so the preliminary estimate is that the parameter format is incorrect, so how should I write the correct one?

Generally, according to normal logic, when we pass application/x-www-form-urlencoded, the parameters should be written like this, but in actual operation, we found that one of them could not get the parameters.

  ({
        baseURL: 'url',
        timeout: 10000,
        headers: { 'Content-Type': 'application/json' }
      }).post('xxx/xxx/xxx',({
          name:'',
          age:12
        }),{
          headers:{
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then(function(response){
          ((response));
        }).catch(function(error){
          (error);
        });

Just add two codes and you can get it normally.

var qs = require('qs');

Then change it to.

var qs = require('qs');  
({
        baseURL: 'url',
        timeout: 10000,
        headers: { 'Content-Type': 'application/json' }
      }).post('xxx/xxx/xxx',({
          name:'',
          age:12
        }),{
          headers:{
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then(function(response){
          ((response));
        }).catch(function(error){
          (error);
        });

Problem to pass values ​​with VUE "application/x-www-form-urlencoded"

Here I am using VUE to describe the "application/x-www-form-urlencoded" value transmission problem

var qs = require('qs')
      let param = {
        'ids':id
      };
      let token = ("token");
      axios
        .post(, (param), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            Authorization: token
          }
        })
        .then(res => {
          ();
          // Toast("Program exception, please try again later");        });
    },

Just change it to

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.