How get request with axios body raw json in vue js

Viewed 6182

send request with postman get answare request like this

screenShot post man

send request with axios in vue js like this:

axios.get("http://url/api/package/questions?language=Persian", {
      headers: {
        'content-type': ' application/json'
      },
      data: {
        "package-slug": "six-dims",
      }}
    )
    .then(res => {
      console.log("my call", res)
    });

get resposne server error 500

1 Answers

You should not use a GET request to send JSON data in body. I suppose you should use either POST, PUT or PATCH to make this HTTP request. I suppose axios doesn't allow you to add data in the post body. You can try this, after changing your method type to POST on your server. But still you can find it out more deeper reading their docs. I have edited the code, you can find out your syntax issue also.

axios.post('http://url/api/package/questions?language=Persian', {'package-slug': 'six-dims'}, { headers: {'Content-Type': 'application/json'}})
 .then(function(result) { 
  console.log(result);
 });
Related