javascript - How get request with axios body raw json in vue js - Stack Overflow

send request with postman get answare request like thissend request with axios in vue js like this:axi

send request with postman get answare request like this

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

send request with postman get answare request like this

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

Share Improve this question edited Aug 3, 2020 at 8:18 Phil 165k25 gold badges262 silver badges267 bronze badges asked Aug 3, 2020 at 8:08 mohammadaprmohammadapr 1901 silver badge9 bronze badges 5
  • 1 You have a leading space before your content-type value. Simply remove the headers since that is the default for Axios anyway. Also, GET requests cannot have data – Phil Commented Aug 3, 2020 at 8:11
  • It does not work without data but in postman have data and request success – mohammadapr Commented Aug 3, 2020 at 8:15
  • 1 If you want to send data, you must use either a POST or PUT request. It will be ignored for a GET request – Phil Commented Aug 3, 2020 at 8:18
  • are you have any solution without use axios ? – mohammadapr Commented Aug 3, 2020 at 8:21
  • I've already told you. Remove the headers and data, ie axios.get("http://url/api/package/questions?language=Persian").then(res => console.log('my call', res)). If you still get a 500 response, check your server's error log – Phil Commented Aug 3, 2020 at 8:22
Add a ment  | 

1 Answer 1

Reset to default 5

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);
 });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742419176a4440337.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信