简体   繁体   English

如何在 Ruby 中创建 POST 请求

[英]How to create POST Request in Ruby

I have functionality where I need send delivery payload with static basic token and additional header.我有需要使用 static 基本令牌和附加 header 发送交付有效负载的功能。

scope = "xapi:read" # some require xapi:read, some require xapi:all
client_auth_header = "Basic <insert token here>"
client_version_header = "1.0.3"
client_site = "<Provided by client>"

I need to do this with post request我需要通过发布请求来执行此操作


curl --request GET \
  --url https://client-url/data/xAPI/agents \
  --header 'Authorization: Basic MjAHYBFHKKMHIKNBGRmOGM0M2RiMDg0M' \
  --header 'X-Experience-API-Version: 1.0.3'

How do I write a post request in ruby?如何在 ruby 中编写发布请求?

with something like this像这样的东西

client.post("/xAPI/statements", body: data.to_json, headers: { "Content-Type" => "application/json" })

what should I replace the client with?我应该用什么替换客户端?

The httparty gem supports a very similar API to what you described here, with HTTParty.post . httparty gem支持与您在此处描述的非常相似的 API ,带有HTTParty.post

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM