最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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);
 });
发布评论

评论列表(0)

  1. 暂无评论