Ruby HTTPS Post问题

时间:2015-08-01 05:22:24

标签: ruby-on-rails ruby https

我有两个代码(故意掩盖变量信息),第一个我收到响应,200代码返回,但第二个我得到403禁止,任何想法?

def get_token()
    http = Net::HTTP.new(server, 443)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?

    #path(a.k.a) ->www.mysite.com/some_POST_handling_script.rb'
    path = '/rest/fastlogin/v1.0?app_key=' + app_key + '&username=%2B' + username + '&format=json'
    puts path

    headers = {'Content-Type'=> 'application/x-www-form-urlencoded', 'Authorization' => password }

    resp, data = http.post(path, data, headers)

    puts 'Code = ' + resp.code
    puts 'Message = ' + resp.message

    resp.each {|key, val| puts key + ' = ' + val}
    puts data
    puts JSON.parse(resp.body)["access_token"]

    result = {}

    result["code"] = resp.code
    result["token"] = JSON.parse(resp.body)["access_token"]

    print  result

    return result
end



def get_token1()
    path = '/rest/fastlogin/v1.0?app_key=' + app_key + '&username=%2B' + username + '&format=json'

    uri = URI.parse('https://' + server + path)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?

    req = Net::HTTP::Post.new(uri.path)
    req["Authorization"] = password

    puts uri.host
    puts uri.path
    puts uri.port
    resp,data = http.request(req)
    print resp 
end

1 个答案:

答案 0 :(得分:2)

我认为这是身份验证问题。您提供的凭据是错误的。这就是403禁止错误发生的原因。