我正在使用 ruby 和 typhoeus-gem 通过其RESTful API将内容上传到 XWiki 页面。这完美地工作。但是在上传标签时,我正在为空格字符而苦苦挣扎。通过 GUI 添加逗号分隔的标签,如“有空格字符,另一个标签”将产生两个标签:“有空格字符”和“另一个标签”。这就是我想要的,但这不适用于 API。上面的示例将导致五个标签除以空格。
- 有
- 空间
- 人物
- 其他
- 标签
API 文档描述了如何向页面添加选项卡。它说,在“application/x-www-form-urlencoded”的情况下,使用字段名称“tag”。如果我使用这种字段类型,只能上传一个标签。重复此操作将覆盖以前的标签。所以我尝试将“标签”作为字段类型,它适用于上传多个标签。但仍然出现如上所述的间距问题。
这是我正在使用的红宝石代码:
url = mainpage_url + "/tags"
tags = "having space characters, another tag"
# HTTP PUT request
request = Typhoeus::Request.new(
url,
ssl_verifypeer: false,
method: :put,
userpwd: "#{username}:#{password}",
headers: {'Content-Type'=> "application/x-www-form-urlencoded;charset=UTF-8"},
body: {tags: tags}
)
# Handling HTTP errors
request.on_complete do |response|
if response.success?
#$log.info("Tags uploaded.")
elsif response.timed_out?
$log.error("Time out: Tags not uploaded.")
elsif response.code == 0
$log.fatal("Could not get http response while uploading Tags. #{response.return_message}")
else
$log.fatal("HTTP request failed while uploading Tags. #{response.code.to_s}")
end
end
request.run
response = request.response
puts response.body
我已经尝试过:
- 将标记空格替换为“+”、“%20”和“\s”。
- 使用 text/plain 和 application/xml 作为媒体类型
我认为 application/xml 可以是解决方案。我尝试了不同的 xml 字符串但没有成功。也许你有我的线索。