【发布时间】:2014-02-06 08:29:02
【问题描述】:
这是我的 curl 命令,在命令行中运行良好:
curl --data @order_new.json \
-H "X-Augury-Token:My_token_goes_here" \
-H "Content-Type:application/json" \
http://staging.hub.spreecommerce.com/api/stores/store_id_goes_here/messages
我需要使用任何类型的 Gem 在 Rails 中实现相同的功能,尝试使用 HTTParty /rest_client / spree-api-client,但这里出了点问题:
require 'httparty'
result = HTTParty.post(
"http://staging.hub.spreecommerce.com/api/stores/52eb347f755b1c97e900001e/messages",
:body => JSON.parse(File.read("order_new.json")),
:header => {
"X-Augury-Token" => "UjjKsdxbrwjpAPx9Hiw4",
"Content-Type" => "application/json"
}
)
但我收到错误,
"The page you were looking for doesn't exist (404)"
我需要与上面 curl 命令等效的 rails,使用 spree-api-client gem 会很有帮助。
【问题讨论】:
-
Curl 正在执行 get 请求,http 方正在执行 post 请求。
-
我怀疑@andHapp,curl 命令会发送
--data参数,所以它应该是POST 请求,而不是GET 请求。 -
哦对了..抱歉错过了!
标签: ruby-on-rails curl rest-client httparty