HTTP POST Request AngularJS

2019-09-08 05:04发布

问题:

I'm actually working on a SparQL viewer but i got an issue with my POST request, someone can told me what's wrong ?

var req = { method: 'POST',
                    url: 'http://dbpedia.org/sparql',
                    headers: { 'Content-type' : 'application/x-www-form-urlencoded',
                               'Accept' : 'application/sparql-results+json' },
                    data: { query : "SELECT * WHERE { <http://dbpedia.org/resource/Awolnation> ?pref ?obj } LIMIT 10",
                            format: "sparql-results+json",
                            timeout : 3000 }
                  };

        $http(req).success(function(data) {
            console.log(data);
        });

EDIT : my bad i forgot the issue

POST http://dbpedia.org/sparql 400 (Bad Request)

回答1:

I think it's a GET query and format=json like :

var req = { 
            method: 'GET',
            url: 'http://dbpedia.org/sparql',
            headers: { 'Content-type' : 'application/x-www-form-urlencoded',
               'Accept' : 'application/sparql-results+json' },
                params: { 
                   query : "SELECT * WHERE { <http://dbpedia.org/resource/Awolnation> ?pref ?obj } LIMIT 10",
                   format: "json"
                }
           };

It's work when Dbpedia endpoint is not down :).