admin管理员组文章数量:1026989
I am trying to connect to the yelp API. Using Vue and Axios. I am unable to connect. I am getting error:
XMLHttpRequest
cannot load ;limit=50. Response for preflight has invalid HTTP status code 500
Here is my code:
new Vue({
el: '#app',
data: {
businesses: []
},
// Logic Methods
mounted() {
var app = this;
var url = ';limit=50';
var config = {
headers: {
"Cache-Control": "no-cache",
'Content-Type': 'application/x-www-form-urlencoded',
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Methods": 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
"Access-Control-Allow-Headers": 'Origin, Content-Type, X-Auth-Token, Accept',
"Access-Control-Max-Age": "1728000",
'Authorization': 'MyAccessCode'
}
};
axios.get(url, config)
.then(function(response) {
console.log(response.headers);
console.log(response);
app.businesses = response.data
})
.catch(function(error) {
app.businesses = "ERROR"
})
}
})
I am assuming this is something to do with CORS but I am unsure how to solve this. I have the CORS Chrome plugin to enable and have all the headers. Can I get any insight on what the problem can be and how to fix it? Is this something on yelp's behalf?
I am trying to connect to the yelp API. Using Vue and Axios. I am unable to connect. I am getting error:
XMLHttpRequest
cannot load https://api.yelp./v3/businesses/search?location=sarnia&limit=50. Response for preflight has invalid HTTP status code 500
Here is my code:
new Vue({
el: '#app',
data: {
businesses: []
},
// Logic Methods
mounted() {
var app = this;
var url = 'https://api.yelp./v3/businesses/search?location=sarnia&limit=50';
var config = {
headers: {
"Cache-Control": "no-cache",
'Content-Type': 'application/x-www-form-urlencoded',
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Methods": 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
"Access-Control-Allow-Headers": 'Origin, Content-Type, X-Auth-Token, Accept',
"Access-Control-Max-Age": "1728000",
'Authorization': 'MyAccessCode'
}
};
axios.get(url, config)
.then(function(response) {
console.log(response.headers);
console.log(response);
app.businesses = response.data
})
.catch(function(error) {
app.businesses = "ERROR"
})
}
})
I am assuming this is something to do with CORS but I am unsure how to solve this. I have the CORS Chrome plugin to enable and have all the headers. Can I get any insight on what the problem can be and how to fix it? Is this something on yelp's behalf?
Share Improve this question edited Jan 25, 2017 at 7:49 Divins Mathew 3,1964 gold badges24 silver badges34 bronze badges asked Jan 25, 2017 at 7:21 Lewis MenelawsLewis Menelaws 1,1865 gold badges21 silver badges45 bronze badges1 Answer
Reset to default 4First things first. The headers you are passing to your request are not meant as request headers:
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Methods": 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
"Access-Control-Allow-Headers": 'Origin, Content-Type, X-Auth-Token, Accept',
"Access-Control-Max-Age": "1728000",
As you can see here they should be used by the server in a response to specify CORS rules. So there is no positive effect by putting them in a request - in fact might be even what's causing the issue (although it should be a 4xx error).
Secondly, the preflight request receiving a 500 typically means that the server has some issue dealing with the request you're making and there is nothing you can do to fix it (in theory). In practice however APIs may often give 500 errors when some request you make is wrong, and by changing it you can obtain a success (wrong implementation but often seen in practice).
You should look into more info regarding the error - start simple (e.g. using Postman or a simple HTTP tool) by providing the minimum of info (e.g. POST https://api.yelp./v3/businesses/search?location=sarnia with your Authorization header only). If successful, add more of the stuff you're actually using (params, different content-type, etc) to see when you get an error.
You can test this way the API itself bypassing Vue, axios and the browser which may change the requests you make. This way you can find out the source of the problem. Again, it's most likely an issue with the server, but just might be caused by something specific in your client's requests.
Good luck!
I am trying to connect to the yelp API. Using Vue and Axios. I am unable to connect. I am getting error:
XMLHttpRequest
cannot load ;limit=50. Response for preflight has invalid HTTP status code 500
Here is my code:
new Vue({
el: '#app',
data: {
businesses: []
},
// Logic Methods
mounted() {
var app = this;
var url = ';limit=50';
var config = {
headers: {
"Cache-Control": "no-cache",
'Content-Type': 'application/x-www-form-urlencoded',
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Methods": 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
"Access-Control-Allow-Headers": 'Origin, Content-Type, X-Auth-Token, Accept',
"Access-Control-Max-Age": "1728000",
'Authorization': 'MyAccessCode'
}
};
axios.get(url, config)
.then(function(response) {
console.log(response.headers);
console.log(response);
app.businesses = response.data
})
.catch(function(error) {
app.businesses = "ERROR"
})
}
})
I am assuming this is something to do with CORS but I am unsure how to solve this. I have the CORS Chrome plugin to enable and have all the headers. Can I get any insight on what the problem can be and how to fix it? Is this something on yelp's behalf?
I am trying to connect to the yelp API. Using Vue and Axios. I am unable to connect. I am getting error:
XMLHttpRequest
cannot load https://api.yelp./v3/businesses/search?location=sarnia&limit=50. Response for preflight has invalid HTTP status code 500
Here is my code:
new Vue({
el: '#app',
data: {
businesses: []
},
// Logic Methods
mounted() {
var app = this;
var url = 'https://api.yelp./v3/businesses/search?location=sarnia&limit=50';
var config = {
headers: {
"Cache-Control": "no-cache",
'Content-Type': 'application/x-www-form-urlencoded',
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Methods": 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
"Access-Control-Allow-Headers": 'Origin, Content-Type, X-Auth-Token, Accept',
"Access-Control-Max-Age": "1728000",
'Authorization': 'MyAccessCode'
}
};
axios.get(url, config)
.then(function(response) {
console.log(response.headers);
console.log(response);
app.businesses = response.data
})
.catch(function(error) {
app.businesses = "ERROR"
})
}
})
I am assuming this is something to do with CORS but I am unsure how to solve this. I have the CORS Chrome plugin to enable and have all the headers. Can I get any insight on what the problem can be and how to fix it? Is this something on yelp's behalf?
Share Improve this question edited Jan 25, 2017 at 7:49 Divins Mathew 3,1964 gold badges24 silver badges34 bronze badges asked Jan 25, 2017 at 7:21 Lewis MenelawsLewis Menelaws 1,1865 gold badges21 silver badges45 bronze badges1 Answer
Reset to default 4First things first. The headers you are passing to your request are not meant as request headers:
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Methods": 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
"Access-Control-Allow-Headers": 'Origin, Content-Type, X-Auth-Token, Accept',
"Access-Control-Max-Age": "1728000",
As you can see here they should be used by the server in a response to specify CORS rules. So there is no positive effect by putting them in a request - in fact might be even what's causing the issue (although it should be a 4xx error).
Secondly, the preflight request receiving a 500 typically means that the server has some issue dealing with the request you're making and there is nothing you can do to fix it (in theory). In practice however APIs may often give 500 errors when some request you make is wrong, and by changing it you can obtain a success (wrong implementation but often seen in practice).
You should look into more info regarding the error - start simple (e.g. using Postman or a simple HTTP tool) by providing the minimum of info (e.g. POST https://api.yelp./v3/businesses/search?location=sarnia with your Authorization header only). If successful, add more of the stuff you're actually using (params, different content-type, etc) to see when you get an error.
You can test this way the API itself bypassing Vue, axios and the browser which may change the requests you make. This way you can find out the source of the problem. Again, it's most likely an issue with the server, but just might be caused by something specific in your client's requests.
Good luck!
本文标签: javascriptHow to stop a quotpreflight has invalid HTTP status code 500quot errorStack Overflow
版权声明:本文标题:javascript - How to stop a "preflight has invalid HTTP status code 500" error? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745658066a2161716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论