我有一个 Rails 5 应用程序和一个表单,我希望用户在其中输入他们的电子邮件地址并添加为联系人。这个问题离我很近。我得到的响应错误是:{"errors":[{"field":null,"message":"access forbidden"}]}
这看起来像一个身份验证问题。这是我的代码...
def email_signup
email_address = params[:email_address]
url = URI("https://api.sendgrid.com/v3/contactdb/recipients")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["authorization"] = 'Bearer <<my_api_key>>'
request["content-type"] = 'application/json'
request.body = "[{\"email\" : email_address}]"
response = http.request(request)
redirect_to jobs_url, notice: response.read_body
end
我错过了什么?