gpt4 book ai didi

ruby-on-rails - 如何将 CURL 请求转换为 Ruby Gem HTTPClient

转载 作者:太空宇宙 更新时间:2023-11-03 16:40:40 25 4
gpt4 key购买 nike

我正在尝试转换此 CURL 请求:

curl \
-F 'slideshow_spec={
"images_urls": [
"<IMAGE_URL_1>",
"<IMAGE_URL_2>",
"<IMAGE_URL_3>"
],
"duration_ms": 2000,
"transition_ms": 200
}' \
-F 'access_token=<ACCESS_TOKEN>' \
https://google.com

到 HTTPClient 请求,但我所有的尝试都导致 400 Bad Request。这是我尝试过的:

  payload = {
"images_urls": [
"https://cdn-m2.esoftsystems.com/10100028/TAASTRUP%40DANBOLIG.DK/10106239925/160596797/BEST_FIT/1542/1024/IMG_5511.jpg",
"https://cdn-m2.esoftsystems.com/10100028/TAASTRUP%40DANBOLIG.DK/10106239925/160596797/BEST_FIT/1542/1024/IMG_5511.jpg",
"https://cdn-m2.esoftsystems.com/10100028/TAASTRUP%40DANBOLIG.DK/10106239925/160596797/BEST_FIT/1542/1024/IMG_5511.jpg"
],
"duration_ms": 2000,
"transition_ms": 200
}

response = RestClient.post url, {slideshow_spec: payload.to_json, multipart: true, access_token: access_token}

有什么想法吗?

最佳答案

您的要求不等同。我猜你在这里混合了 JSONMultipartx-www-form-urlencoded 格式。

RestClient 支持所有三种格式(示例取自 https://github.com/rest-client/rest-client/blob/master/README.md )

# POST JSON
RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json}

# POST Multipart
# Usually not needed if you don't want to upload a file
RestClient.post '/data', {:foo => 'bar', :multipart => true}

# POST x-www-form-urlencoded
RestClient.post('https://httpbin.org/post', {foo: 'bar', baz: 'qux'})

看起来您的 curl 示例使用 application/x-www-form-urlencoded,而您的 Ruby 示例使用 multipart/form-data

一些背景信息,检查

关于ruby-on-rails - 如何将 CURL 请求转换为 Ruby Gem HTTPClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54554952/

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