HTTP POST Request AngularJS

早过忘川 提交于 2019-12-11 20:21:19

问题


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



来源:https://stackoverflow.com/questions/29435797/http-post-request-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!