【发布时间】:2019-06-01 21:36:25
【问题描述】:
我正在尝试使用通过 statistics.gov.scot 提供的 SPARQL 端点获取一些公开可用的数据。 API page 建议使用 POST。
选项 1:POST(推荐) 向端点发出 POST,正文中包含查询,以及 sparql-results+json 的 Accept 标头:
POST http://statistics.gov.scot/sparql HTTP/1.1 Host: statistics.gov.scot Accept: application/sparql-results+json Content-Type: application/x-www-form-urlencoded query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10
问题
我正在尝试运行查询,该查询将以下列方式生成包含可用地理位置的表:
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 }
【问题讨论】:
-
我认为,您的 httr POST 请求网址上有一个
.csv扩展名不应该存在。 -
真的!我可以想到 TO 在 Web 界面中单击了 "Downloads -> CSV",通常默认为一个名为
sparql.csv的文件 - 这里的小错字会产生巨大的影响。
标签: r post httprequest sparql httr