"My query", "per_page" => "50"}) 只使用原始字符串而不是表单?-6ren">
gpt4 book ai didi

ruby - 发布原始字符串而不是表单数据?

转载 作者:数据小太阳 更新时间:2023-10-29 08:37:51 24 4
gpt4 key购买 nike

你是怎么做到的:

response = Net::HTTP.post_form(uri, {"q" => "My query", "per_page" => "50"})

只使用原始字符串而不是表单?像这样的东西:

response = Net::HTTP.normal_post(uri, "My dog likes to walk in the forest")

最佳答案

我一直在搜索并找到了这个答案(在另一个网站上)

url = URI.parse(“http://api.domain.com”)
begin
requestXml = “John john1234”
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url.path)
request.body = requestXml
request["Content-Type"] = “application/xml”
response = http.request(request)
response.code # => 200 Ok
response.body # => The body (HTML, XML, blob, whatever)
rescue
logger.debug “Error #{$!}”
end

归功于:

http://www.blog.openshell.in/2011/03/nethttp-raw-post-ruby-code/

关于ruby - 发布原始字符串而不是表单数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24886973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com