简体   繁体   中英

HTTP POST Request AngularJS

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)

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 :).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM