Ruby HTTP请求401未经授权

时间:2014-10-18 01:25:09

标签: ruby api http request

请求更改此API请求,但是我们的ruby dev几个月前就离开了,我们只有一个站点使用它。下面的代码是我目前的代码,我设法修复任何语法错误,或者我认为。当然这是我第二天与红宝石合作。

它旨在将电话号码发送出去并获得短信。但是我一直遇到401错误。

只是我删除了身份验证码。我不知道这是不是很重要,或者现在觉得这样做是件好事。

最初这是向我提出要求的方式,我试图重用已经存在的要求。

{"msisdns":["Phone Number"],"mobileFlow":"xxxxxxxx"}

以下标题应与帖子一起提供:

'Content-Type:application/json', 'Accept:application/json', 'Authorization: xxxx-xxx-xxxx'

代码是:

def mobile_club
require 'rest_client'

phone_number = params[:phone_number].gsub(/[^0-9]/, "")
if(phone_number.length != 10)
  redirect_to '/whats-fresh/lets-connect', notice: 'Please enter a 10 digit phone number'
  return
end

  phone_number = "+1#{phone_number}"

        $auth = 'basic', 'Authorization:xxxx-xxx-xxxx-xxxx-xxxx'

  response = RestClient.post "http://go2advertisingmobile.com/api/v1/messaging/sendContent", { 'msisdns' => [phone_number], 'mobileFlow' => 'xxxxxxxxxxxxxxxxxxx'}.to_json, :content_type => :json, :accept => :json, :Authorization => $auth

  puts response.code

if response.code == 201
  redirect_to '/whats-fresh/lets-connect', notice: 'Thank you for signing up for the mobile club!'
else
  logger.debug response
  redirect_to '/whats-fresh/lets-connect', notice: "Mobile Club signup failed (#{response.to_str})"
end
end    

我感谢所有的帮助和指示。

0 个答案:

没有答案