0
我有,我用它來查詢SPARQL端點PoolParty這curl命令:Poolparty SPARQL使用端點的Java /球衣
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: text/html" -d 'format=application/json&query=PREFIX skos:<http://www.w3.org/2004/02/skos/core#> select ?label { <http://thesaurus.iadb.org/publicthesauri/110246602490720414534842> skos:prefLabel ?label .}' http://localhost:8086/PoolParty/sparql/publicthesauri
現在我想做的使用的Java/Jersey客戶端相同的查詢。我的Maven的依賴關係是:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-jetty-connector</artifactId>
<version>2.23.1</version>
</dependency>
,我試過的代碼是:
公共字符串getLabels(查詢字符串){
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target("http://localhost:8086");
webTarget.path("/PoolParty/sparql/publicthesauri");
Form form = new Form().param("format", "application/json")
.param("query", query);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.TEXT_HTML);
invocationBuilder.header("Content-Type", "application/x-www-form-urlencoded");
Response response = invocationBuilder.post(Entity.form(form));
return response.readEntity(String.class));
}
此代碼假設做同樣的呼籲,我的curl命令但是,我能夠查詢Poolparty SPARQL端點如果查詢,但我不能用該方法做到這一點,關於我在做什麼錯誤的方法的任何想法?
感謝 路易斯