问题
When issuing a SPARQL CONSTRUCT query to a specific endpoint, Apache Jena library 3.14.0 issues an error message as follows.
Endpoint returned Content Type: application/sparql-results+xml which is not a valid RDF syntax
The code I wrote is as follows.
QueryEngineHTTP qeh = new QueryEngineHTTP(endpointUrl, rq);
qeh.setAcceptHeader("application/rdf+xml");
Model m = qeh.execConstruct();
The endpoint is https://id.nlm.nih.gov/mesh/sparql
.
The query is as follows.
CONSTRUCT {?s <http://id.nlm.nih.gov/mesh/vocab#altLabel> ?o}
FROM <http://id.nlm.nih.gov/mesh/2020>
WHERE {
?s <http://id.nlm.nih.gov/mesh/vocab#altLabel> ?o ;
a <http://id.nlm.nih.gov/mesh/vocab#Term> .
FILTER(isLiteral(?o))
} LIMIT 3
When issuing this query by the curl tool, I got a fine result.
% curl -LH 'Accept: application/rdf+xml' --data-urlencode query@test.rq https://id.nlm.nih.gov/mesh/sparql
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="http://id.nlm.nih.gov/mesh/vocab#">
<rdf:Description rdf:about="http://id.nlm.nih.gov/mesh/2020/T000963157">
<j.0:altLabel xml:lang="en">Topics, Exhibitions as</j.0:altLabel>
</rdf:Description>
<rdf:Description rdf:about="http://id.nlm.nih.gov/mesh/2020/T000950545">
<j.0:altLabel xml:lang="en">Psychiatric Fetishism</j.0:altLabel>
</rdf:Description>
<rdf:Description rdf:about="http://id.nlm.nih.gov/mesh/2020/T000950541">
<j.0:altLabel xml:lang="en">Psychological Extraversion</j.0:altLabel>
</rdf:Description>
</rdf:RDF>
来源:https://stackoverflow.com/questions/64887803/strange-behavior-of-content-negotiation-concerning-sparql-construct-query