- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在关注 these instructions提交 SPARQL 查询,首选 POST 方法,因为查询可能很长。但即使 GET 有效,它似乎也失败了 - 有什么方法可以使 POST 查询有效?
sparql = <<END
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P31 wd:Q146.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
END
# Fails with 405 Not writable
resp = Excon.post('https://query.wikidata.org/sparql', body: "query=#{URI::encode(sparql)}")
puts resp.status, resp.body
# Works with 200
resp = Excon.get("https://query.wikidata.org/sparql?query=#{URI::encode(sparql)}")
puts resp.status, resp.body
我也试过发送 "Content-Type"=> "application/x-www-form-urlencoded"
,但没有成功。
最佳答案
感谢上面的评论者展示了工作示例。我根据所有明显的组合做了一些进一步的检查,如下所示。
总结:
user-agent
header ,并注意某些库默认情况下不会包含一个 header (否则它会返回无法解释的 403)require 'excon'
# any arbitrary query
sparql = 'SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q146. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }'
# SUCCESS!
resp = Excon.get("https://query.wikidata.org/sparql?query=#{URI::encode(sparql)}")
puts "GET", resp.status, resp.body[0,100], "\n"
# FAIL! 403 (need user agent)
headers = { "Content-Type" => "application/sparql-query" }
resp= Excon.post('https://query.wikidata.org/sparql', body: sparql, headers: headers)
puts "POST sparql-query", resp.status, resp.body[0,100], "\n"
# SUCCESS!
headers = { "Content-Type" => "application/sparql-query", "User-Agent" => "Ruby 2.6.4" }
resp= Excon.post('https://query.wikidata.org/sparql', body: sparql, headers: headers)
puts "POST sparql-query with user-agent", resp.status, resp.body[0,100], "\n"
# FAIL! 403 (need user agent)
headers = { "Content-Type" => "application/x-www-form-urlencoded" }
resp = Excon.post('https://query.wikidata.org/sparql', body: "query=#{URI::encode(sparql)}", headers: headers)
puts "POST form", resp.status, resp.body[0,100], "\n"
# SUCCESS!
headers = { "Content-Type" => "application/x-www-form-urlencoded", "User-Agent" => "Ruby 2.6.4" }
resp = Excon.post('https://query.wikidata.org/sparql', body: "query=#{URI::encode(sparql)}", headers: headers)
puts "POST form with user-agent", resp.status, resp.body[0,100], "\n"
# FAIL! 405 (need encoding)
resp = Excon.post('https://query.wikidata.org/sparql', body: "query=#{URI::encode(sparql)}")
puts "POST plain", resp.status, resp.body[0,100], "\n"
# FAIL! 405 (need encoding)
headers = { "User-Agent" => "Ruby 2.6.4" }
resp = Excon.post('https://query.wikidata.org/sparql', body: "query=#{URI::encode(sparql)}", headers: headers)
puts "POST plain with user-agent", resp.status, resp.body[0,100], "\n"
更多信息
关于ruby - POST(而非 GET)维基数据查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58041367/
正如标题所说,我需要制作一个函数,在二进制补码中的 2 个碱基、DEC 和 HEX 之间进行转换。该值使用的位数从一开始就已知。 在深入研究之后,我发现了以下算法: 给定一个 DEC 中的数字。 获取
我的用户文档具有以下格式: { userId: "", userAttributes: [ "", "", ... ""
根据这个: Selectivity is the value between 0 and 1, and it is the fraction of rows returned after applyi
这个词有它 FillChar 是用相同值的字节填充内存补丁的最快方法(不是零,因为有 ZeroMemory),但是是否有等效于用相同的序列填充内存(四字节)整数或基数?像 FillInt 或 Fill
我正在努力寻找建模 1 : 0,1 关系的最佳方法(“可能有一个”或“最多有一个”)。我相信这被称为 Z 基数。 例如,假设我有两个类 Widget和 WidgetTest .并非所有 Widget
我使用parseInt找到了一个片段;它用于获取窗口高度。 这是代码: parseInt($(window).height(), 20); 我很困惑为什么使用 20 作为第二个参数。为什么不是 10
要将十进制数转换为基数 2,我使用: int base2 = 10; Convert.ToString(base2, 2); 输出:1010 但是我怎么能做相反的事情呢?即: 输入:1010输出:10
这是一张真实 table 的再现。假设我有这段代码: CREATE TABLE `testTable` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
由于十六进制(基数 16)使用 0-9A-F,并且(我在这里假设)基数 17 使用 0-9A-G,依此类推。什么符号用过一次0-9A-Z都用完了。 最佳答案 你的问题没有标准答案。 “Base 36”
我正在寻找支持 radix 的浏览器列表Number.toString() 中的参数在 JavaScript 中。全部执行toString ,但我找不到他们是否都支持 radix toString 的
这个问题已经有答案了: What is the radix parameter in Java, and how does it work? (6 个回答) 已关闭 5 年前。 public clas
为什么 (73).toString(36) 返回 21 而 (0.73).toString(36) 返回 0。 qa2voha2volfpsnhmyhqia4i 而不是 0.21? 最佳答案 这是因为
我目前正在研究数据库,我看到 degree 和 cardinality 用作相同的术语,或在某些其他学位定义为否。关系中涉及的实体的数量,并进一步分类为一元、二元和三元。 某些放置度数定义为关系类型的
UML(统一建模语言)中的运算符*和运算符0..*有什么区别? 我看到了这两个基数运算符,但是现在我不必使用哪个基数运算符了。 最佳答案 符号“*”是“0 .. *”的快捷方式。在这种情况下使用的正确
我有位于目录“someApp”中的 Angular 应用程序。网址是 http://example-domain/someApp/#/对于一些带有路径的状态 url 是:http://example-
我想一劳永逸地知道如何编写 UML 基数,因为我经常不得不讨论它们(因此非常欢迎证据和来源:) 如果我想解释一下 Mother可以有几个Child任但是 Child有一个而且只有一个 Mother ,
进行字符算术时,规则是以 10 为基数还是以 8 为基数进行计算?我的书上说'A' = 101(基数为8)或65(基数为10),但是当我将基数为8的字符值插入到我的书给出的关于说明这一点的示例中时,我
该程序是将 4 进制数转换为 2 进制数,并且应该就地完成 #include #include void shiftr(char num[],int i) { memmove(num+i,n
这个问题已经有答案了: JavaScript parseInt is giving me wrong number, what I'm doing wrong? [duplicate] (1 个回答)
我遇到了一个小错误,它似乎表明当您传入图像数据作为其源时,在图像完全加载之前调用了 onload 函数。 这是 HTML 这是 JavaScript: var can
我是一名优秀的程序员,十分优秀!