我试图使用通过statistics.gov.scot提供的SPARQL端点获取一些公开可用的数据。API页面建议使用POST。
选项1: POST (推荐)向端点发出一个POST,其中包含正文中的查询,以及sparql-+json的接受头: POST http://statistics.gov.scot/sparql HTTP/1.1主机: statistics.gov.scot接受:statistics.gov.scot/sparql-结果+json内容-类型:application/x表单-urlencoded statistics.gov.scot
问题
我试图以以下方式运行查询,该查询将生成一个具有可用地理位置的表:
response <- httr::POST(
url = "http://statistics.gov.scot/sparql.csv",
query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?hierarchy ?label
WHERE { ?hierarchy
rdfs:subPropertyOf
<http://statistics.gov.scot/def/hierarchy/best-fit> ;
rdfs:label ?label } ")结果返回错误响应的代码:
httr::status_code(response)
[1] 400查询
当对基于web的enpoint接口(https://statistics.gov.scot/sparql-beta)进行测试时,查询工作得很好。
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?hierarchy ?label
WHERE {
?hierarchy
rdfs:subPropertyOf <http://statistics.gov.scot/def/hierarchy/best-fit> ;
rdfs:label ?label }发布于 2019-06-02 13:56:12
JSON
response <- httr::POST(
url = "http://statistics.gov.scot/sparql", accept("application/sparql-results+json"),
body = list( query = "SELECT * { ?s ?p ?o } LIMIT 10" )
)
content(response, "text")或(特定端点)
response <- httr::POST(
url = "http://statistics.gov.scot/sparql.json",
body = list( query = "SELECT * { ?s ?p ?o } LIMIT 10" )
)
content(response, "text")CSV
response <- httr::POST(
url = "http://statistics.gov.scot/sparql", accept("text/csv"),
body = list( query = "SELECT * { ?s ?p ?o } LIMIT 10" )
)
content(response, "text")或(特定端点)
response <- httr::POST(
url = "http://statistics.gov.scot/sparql.csv",
body = list( query = "SELECT * { ?s ?p ?o } LIMIT 10" )
)
content(response, "text")https://stackoverflow.com/questions/56410607
复制相似问题