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 theheaders
since that is the default for Axios anyway. Also, GET requests cannot havedata
– 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
anddata
, ieaxios.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
1 Answer
Reset to default 5You 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);
});