-1
我張貼到接受捲曲如下的API:如何使用RestClient作爲URL參數發佈?
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})
出於某種原因,該數據是罰款所有除了「輸入',它總是以數組的形式得到一個錯誤,由於字符串是預期的,所以它會觸發一個錯誤。請注意下面的輸入參數是一個數組。
{"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)
什麼是錯誤? – 2014-10-07 19:57:32
爲什麼不使用[Curb](https://github.com/taf2/curb),它很好地包裝了libcurl。 – 2014-10-07 20:45:28
+1 to'curb'。更好的是,如果你做了很多HTTP工作:[法拉第](https://github.com/lostisland/faraday)。 – tadman 2014-10-07 20:47:29