gpt4 book ai didi

ruby - 在 Ruby 中面对 Net::HTTP Get 的问题

转载 作者:数据小太阳 更新时间:2023-10-29 07:39:23 25 4
gpt4 key购买 nike

这是我想在 ruby​​ 中转换的 curl 请求:

curl -k --get --data 'session.id=48d59b37-5875-4e49-8d79-6cf097d740f&ajax=executeFlow&project=test&flow=two' https://localhost:8443/executor

我应该这样回应:

{
"message" : "Execution submitted successfully with exec id 688",
"project" : "test",
"flow" : "two",
"execid" : 688
}

我将其转换为以下 ruby​​ 代码:

require 'json'
require 'uri'
require 'net/http'

url = URI("https://localhost:8443/executor")
http = Net::HTTP.new(url.host, url.port)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.use_ssl = (url.scheme == 'https')
request = Net::HTTP::Get.new(url.request_uri)
request.set_form_data({'session.id' => '48d59b37-5875-4e49-8d79-6cf097d740f', 'ajax' => 'executeFlow', 'project' => 'test', 'flow' => 'two'})
response = http.request(request)
puts response

但这会引发错误页面的 html 代码,而不是预期的响应。我在这里做错了什么?

最佳答案

这来自 Net::HTTP文档,我还没有测试过。

url = URI("https://localhost:8443/executor")
request = Net::HTTP::Post.new(url)
request.set_form_data({'session.id' => '48d59b37-5875-4e49-8d79-6cf097d740f', 'ajax' => 'executeFlow', 'project' => 'test', 'flow' => 'two'})

response = Net::HTTP.start(url.hostname, url.port, use_ssl: url.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
http.request(request)
end

关于ruby - 在 Ruby 中面对 Net::HTTP Get 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26087817/

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