Closed faysal515 closed 8 years ago
Please provide a sample code of the request you are trying out to see if it's related with any CORS issue
Meteor.methods({
'fetchFromService': function( ) {
// Create our future instance.
var future = new Future();
HTTP.get( 'https://play-fetch.herokuapp.com/app/com.opera.mini.native.beta', {}, function( error, response ) {
if ( error ) {
future.return( error );
} else {
future.return( response );
}
});
return future.wait();
}
});
I work in meteor, it's server side method. it returns response but the one that i mentioned in the hurl service.
Using a vanillajs ajax request works perfectly:
/**
* Vanilla XMLHttpRequest wrapper
*
* @param Object config
* @param String data
* @param String url
* @param Function success
* @param Function error
*/
var http = function(config) {
var req = new XMLHttpRequest();
var method = (config.data) ? "POST" : "GET";
req.open(method, config.url, true);
req.setRequestHeader('User-Agent','XMLHTTP/1.0');
if (config.data) {
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
}
req.onreadystatechange = function () {
if (req.readyState != 4) return;
if (req.status != 200 && req.status != 304) {
if ( typeof config.error != "function" ) {
console.log(req.status+": "+ req.response);
} else {
config.error(req.status, req.response);
}
return;
}
config.success(req.response)
};
if (req.readyState == 4) return;
req.send(config.data);
};
http({
url: "https://play-fetch.herokuapp.com/app/com.opera.mini.native.beta",
success: function(data) {
console.log(data);
}
})
The only difference i can see here is the UA header setup, maybe Heroku blocks any non-UA identified request. Hope it helps!
Thanks. made it work with vanilla JS.
Hi there!
I'm having trouble sending GET requests to the API programatically. If I access a URL like [this]() in the browser, I get a JSON response as expected. If I make a GET request in my code, however, I get a 503 Application Error from Heroku. Can you advise on this?
For example, here is what I see with this URL in the browser:
And here is what I see if I make a request via the hurl.it service (I get the same error in my code):
Do I need to include any special HTTP headers with my request or other info? Any advice on how to fix this error?