【问题标题】:How to add http headers to Apache Jena QueryEngineHTTP query?如何将 http 标头添加到 Apache Jena QueryEngineHTTP 查询?
【发布时间】:2017-02-09 10:36:26
【问题描述】:

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

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

【问题讨论】:

    标签: rest http-headers jena


    【解决方案1】:

    Apache Jena 现在(v3.1.1 及更高版本)提供了传入具有必要安全设置的 HttpClient 的方法。

    Docmentation

    ... set up an appropriate HttpClient for authentication ....
    
    QueryExecution execution = QueryExecutionFactory.sparqlService( ... , httpClient)
    

    【讨论】:

      猜你喜欢
      • 2013-02-14
      • 1970-01-01
      • 2014-11-03
      • 2012-08-14
      • 2017-10-15
      • 2012-01-04
      相关资源
      最近更新 更多