我试图从 Stardog 三重存储中获取一些数据到 Angular 中,但我真的很难让它工作。我使用完全相同的标头和参数从 curl 访问服务没有问题。我还尝试省略参数部分,只输入完整的 url ('localhost:5820/myDB/query?reasoning=false&query=SELECT * WHERE {?s ?p ?o}') 没有运气。
private _queryUrl = 'http://localhost:5820/myDB/query';
constructor(private _http: Http) {}
getData() {
let username : string = 'admin';
let password : string = 'admin';
let headers = new Headers();
headers.append('Authorization', "Basic " + btoa(username + ":" + password));
headers.append('Content-Type', 'application/rdf+xml');
headers.append('Accept', 'application/sparql-results+json');
let params = new URLSearchParams();
params.set('reasoning', 'false');
params.set('query', 'SELECT * WHERE {?s ?p ?o}');
let options = new RequestOptions({ headers: headers, search: params });
return this._http
.get(this._queryUrl, options)
.map((res: Response) => res.json());
}