Ruby 如何使用RestClient作为URL参数发布?

Ruby 如何使用RestClient作为URL参数发布?,ruby,post,rest-client,Ruby,Post,Rest Client,我将发布到一个接受CURL的API,如下所示: curl -v -X POST "https://url.com" -d 'input=frustrated&user_key=3b9ccb48e734fce6b982a9c1c2cef301' 我尝试了以下操作,但出现了错误: data = {'user_key' => "#{ENV['USER_KEY']}", 'input' => "#{text}", 'client_name'=>> "#{cli

我将发布到一个接受CURL的API,如下所示:

curl -v  -X POST "https://url.com" -d 'input=frustrated&user_key=3b9ccb48e734fce6b982a9c1c2cef301'
我尝试了以下操作,但出现了错误:

    data = {'user_key' => "#{ENV['USER_KEY']}", 'input' => "#{text}", 'client_name'=>> "#{client_name}"}
    talkresponse = JSON.parse(RestClient.post url_talk_bot, {:params => data})
出于某种原因,除了“input”之外,所有的数据都很好,因为“input”总是以数组的形式获取一个错误,该数组会触发一个错误,因为需要一个字符串。下面请注意输入参数是如何成为数组的

{"user_key"=>"3b9ccb48e734fce6b982a9c1c2cef301", "input"=>"[\"frustrated how do I post to params, worked fine before\"]", "client_name"=>"14155086888"}

 /mnt/task/__gems__/gems/rest_client-1.7.3/lib/restclient/abstract_response.rb:48:in `return!': 401 Unauthorized (RestClient::Unauthorized)

我在使用RestClient.post时遇到了类似的问题。 以至于我停止使用.post,开始使用.execute

  • RestClient.post uri,{:params=>data}
变成

  • RestClient.execute({:method=>:post,:url=>uri,:headers=>{api_key:'123',authorization:Base64::encode(“#{user}:#{password},:payload:body})

为什么不使用,它很好地包装了libcurl。+1到
抑制
。如果你做了大量的HTTP工作,那就更好了:.ugh--这是否意味着需要寻找rest客户端以外的另一个HTTP客户端?