开发者

Ruby on Rails HTTPS Post Bad Request

Greetings all.

My application works with a remote server. Server uses https authorization of the certificate. I have following code to authorize and sends request:

uri = URI.parse("https://db1-test.content.ertelecom.ru/")
http = Net::HTTP.new(uri.host, '443')
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_file = File.join(File.dirname("public/certificate.pem"),
"certificate.pem")
http.start do |http|
      req =
Net::HTTP::Get.new("/cgi-bin/e开发者_JAVA技巧xpr/export.get_pay_systems?partner_id=1003")
      responce = http.request(req)
      resp = responce.body
end

this code works well, I get the data from the server. BUT when I try to make POST request:

http.start do |http|
      req =
Net::HTTP::Post.new("/cgi-bin/expr/payment_transactions.verify_order",
params)
      responce = http.request(req)
      resp = responce.body
end

I get an error from the server:

Your browser sent a request that this server could not understand.
Request header field is missing ':' separator.

what is that be? I tried to find a solution, but to no avail. the Internet caught the message that it could be antivirus, but I'm on Linux. I will be glad to any thoughts!


You're not filling the header data.

You could either use the Net::HTTP.post_form method to create your request or populate the form_data yourself.

post_form solution:

req = NET::HTTP.post_form("/cgi-bin/expr/payment_transactions.verify_order", params)

manual form_data population

req =
  Net::HTTP::Post.new("/cgi-bin/expr/payment_transactions.verify_order")
req.set_form_data(params)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜