HTTParty headers 在 ruby 脚本中不工作

HTTParty headers not working in ruby script

我正在尝试在一些 Ruby 代码中复制以下 curl 命令(有效),但是 'Customer-Id' header 部分似乎没有得到 sent/picked由 API.

curl 命令是: curl -u ‘me@mydomain.com’ -H ‘Customer-Id: 243’ https://192.168.50.50/api/customers

关于该客户的 returns 信息。但是在 Ruby 中,以下内容不起作用:

auth = {
  username: “me@mydomain.com”,
  password: "#{pass}"
}

@result = HTTParty.get("https://192.168.50.50/api/customers",:basic_auth => auth, :headers => { ‘Customer-Id: 243’ } ).parsed_response
puts @result

如果有人知道我在这里做错了什么,将不胜感激!

查看你的代码,有一个错误:

:headers => { ‘Customer-Id: 243’ }

试试这个方法:

:headers => {'Customer-Id' => 243}