2017-02-09 91 views
0

我正在尝试使用HTTP标头,以便我可以验证我的应用程序以查询ORCID(http://orcid.org)公共API。我创建这样的标题:如何将http标头添加到Apache Jena QueryEngineHTTP查询?

HttpOptions httpOptions = new HttpOptions(); 
Header contentTypeHeader = new BasicHeader("Content-Type", "application/orcid+json"); 
Header authorizationHeader = new BasicHeader("Authorization", "Bearer 5266384f-0567-43f0-9cd4-bc6f6a5dc3ea"); 
Header[] headers = new Header[2]; 
headers[1] = contentTypeHeader; 
headers[2] = authorizationHeader; 
httpOptions.setHeaders(headers); 

但我不知道如何将这些标题放到我的查询中。我在写我的查询是这样的:

QueryExecution execution = new QueryEngineHTTP(endpoint, query); 

使用org.apache.jena.sparql.engine.http.QueryEngineHTTP

回答

0

阿帕奇现在耶拿(V3.1.1及更高版本)提供的手段来传递在具有必要安全设置的HttpClient中。

Docmentation

... set up an appropriate HttpClient for authentication .... 

QueryExecution execution = QueryExecutionFactory.sparqlService(... , httpClient)