Vue JS how to accept the URLEncoded format

Viewed 1589

I am trying to accept the URL Encoded format in postman to post some data to the Vue JS app, I am using the below-encoded format, how can I achieve that which npm package should I use?

enter image description here

3 Answers

you can use axios

const axios = require('axios')


const params = new URLSearchParams()
params.append('name', 'Akexorcist')
params.append('age', '28')
params.append('position', 'Android Developer')
params.append('description', 'birthdate=25-12-1989&favourite=coding%20coding%20and%20coding&company=Nextzy%20Technologies&website=http://www.akexorcist.com/')
params.append('awesome', true)

const config = {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
}

axios.post(url, params, config)
  .then((result) => {
    // Do somthing
  })
  .catch((err) => {
    // Do somthing
  })

x-www-form-urlencoded data is sent via HTTP headers

Most HTTP headers are not visible to your front-end JavaScript application. They are only visible to the server responding to the request. You cannot read them directly from JavaScript running in a web browser.

However, there are options...

  • Change the source; have the POST request changed to a GET and encode the parameters in the URL
  • A reverse proxy for your application could convert from POST parameters to GET parameters with some additional coding or configuration
  • Receive the request on your server and feed them into your Vue.js application; use something like php/asp/etc to serve your html instead of static HTML files and embed the posted parameters in the generated HTML page

There may be other options if you are creative, but the simplest is the first - just change the source so it no longer posts data.

I resolved it by adding middleware(server-side code such as .net web API) and then redirected it using query string)

Related