0
所以,如果我執行下面的命令,它工作正常:麻煩與NET/HTTP POST數據
curl -X POST --compressed -H "Content-Type:application/json" \
-H 'x-api-user: USER_ID' \
-H 'x-api-key: API_TOKEN' \
-d '{"text":"from the api!","type":"todo"}' \
https://habitrpg.com/api/v1/user/task
我試圖讓HTTParty工作,但他們對連接壓縮文件基本上是不存在的,在我的理解水平。我嘗試過使用NET/HTTP,並且可以建立連接,但是API不斷給我提供錯誤,說明我的數據錯誤(它說我沒有給它一個有效的類型)。這裏是我使用的代碼:
data = {:text => "from the app dog", :type => "todo"}
uri = URI.parse("https://habitrpg.com/api/v1/user/task")
http = Net::HTTP.new(uri.host, uri.port)
http.set_debug_output($stdout)
http.use_ssl = true
resp = http.post(uri.request_uri, data, {"x-api-user" => USER_ID, "x-api-key" => API_TOKEN})
resp.body
我也嘗試了所有的數據如下:
data = {:text => "from the app dog", :type => "todo"}.to_json.to_s
data = "{\"text\":\"from the app dog\",\"type\":\"todo\"}"
data = "'" + "{\"text\":\"from the app dog\",\"type\":\"todo\"}" + "'"
,也許三四個,我再也不能識別其他的事情。有沒有人有什麼建議?我處於全面虧損狀態。
你不知道多麼愚蠢,讓我感覺。我認真地花了30分鐘搞亂那串。 – 2013-03-23 22:23:16