$http.get request return status -1 for one specific WebService

Hello everyone,
I’m trying to get dynamic data from a public WebService URL1 using get method in http, it works fine in browser but when i run it with “ionic serve” or directly on device, the get request is not processed and returns status -1.
Replacing the URL by another one in my code (for example URL2) without changing anything else works fine.
URL1 : https://openlibrary.org/api/books?bibkeys=ISBN:9782091841762&format=json&jscmd=data
URL2 : http://date.jsontest.com/

Here’s my Controller :

.controller(‘AppCtrl’, function($scope,$http) {
$scope.data = {isbn:‘’};
$scope.result=‘’;
// for debug
$scope.status = ‘’;
$scope.data = ‘’;
$scope.headers = ‘’;
$scope.config = ‘’;
$scope.showResponse = false;

$http.get('http://openlibrary.org/api/books?bibkeys=ISBN:9782091841762&format=json&jscmd=data')
.success(function(data, status, headers,config){
      console.debug("http get success");
      $scope.showResponse = true;
      $scope.data = data;
      $scope.status = status;
      $scope.headers = headers;
      $scope.config = config;
      console.debug("Request finished with status "+status);
      console.debug("URL : "+config.url);
      console.debug("Method : "+config.method);
      console.debug("Headers : "+config.headers);
      console.debug("Data : "+data);
    }).error(function(data, status, headers,config) {
        console.debug("Error status : " + status);
        //console.debug("headers : " + headers);
        //console.debug("config : " + config);
        $scope.showResponse = true;
        $scope.data = data;
        $scope.status = status;
        $scope.headers = headers;
        $scope.config = config;
        console.debug("Request finished with status "+status);
        console.debug("URL : "+config.url);
        console.debug("Method : "+config.method);
        console.debug("Headers : "+config.headers);
        console.debug("Data : "+data);
      });

})

Here is the result obtained with URL1 :

0 409636 debug Error status : -1
1 409637 debug Request finished with status -1
2 409637 debug URL : https://openlibrary.org/api/books?bibkeys=ISBN:9782091841762&format=json&jscmd=data
3 409638 debug Method : GET
4 409639 debug Headers : {“Accept”:“application/json, text/plain, /”}
5 409639 debug Data : null

Here is the result obtained with URL2 :slight_smile:

0 298747 debug http get success
1 298748 debug Request finished with status 200
2 298748 debug URL : http://date.jsontest.com/
3 298749 debug Method : GET
4 298750 debug Headers : {“Accept”:“application/json, text/plain, /”}
5 298751 debug Data : {“time”:“10:28:18 AM”,“milliseconds_since_epoch”:1465727298684,“date”:“06-12-2016”}

I have searched for hours now and don’t have the beginning of a clue, so thank you in advance for your help.

Hi egave,
It looks like the request is cancelled (is visible in a Chrome Debugger). Which does not help much…
Have you had a chance to solve the issue?
Was it somehow related to SSL by any chance?
Any clue appreciated.
Cheers.

I tried to call your url from console and I see that you response is not JSON

192:~ greg$ http https://openlibrary.org/api/books?bibkeys=ISBN:9782091841762&format=json&jscmd=data
[1] 15437
[2] 15438
[2]+  Done                    format=json
192:~ greg$ HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/javascript
Date: Thu, 08 Dec 2016 19:55:07 GMT
Server: nginx/1.4.6 (Ubuntu)
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-OL-Stats: "IB 1 0.036 MC 1 0.001 TT 0 0.037"

var _OLBookInfo = {"ISBN:9782091841762": {"bib_key": "ISBN:9782091841762", "preview": "noview", "thumbnail_url": "https://covers.openlibrary.org/b/id/3082801-S.jpg", "preview_url": "https://openlibrary.org/books/OL12402003M/Conjugaison_junior", "info_url": "https://openlibrary.org/books/OL12402003M/Conjugaison_junior"}};

Maybe this is a problem…