带有标头的Ruby https POST [英] Ruby https POST with headers

查看:109
本文介绍了带有标头的Ruby https POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试过了:

  uri = URI.parse(https:// ...)
https = Net :: HTTP.new(uri.host,uri.port)
req = Net :: HTTP :: Post.new(uri.path)
req ['foo'] = bar
res = https.request(req)
puts res。 body


解决方案

这是一个json的问题。这解决了我的问题。无论如何,我的问题并不清楚,所以赏金去Juri

  require'uri'
require'net / http'
require'net / https'
require'json'

@toSend = {
date=> 2012-07-02,
aaaa=> bbbbb,
cccc=> dddd
} .to_json

uri = URI.parse(https:/ ...)
https = Net :: HTTP.new(uri.host, uri.port)
https.use_ssl = true
req = Net :: HTTP :: Post.new(uri.path,initheader = {'Content-Type'=&'application / json'} )
req ['foo'] ='bar'
req.body =[#{tosend}]
res = https.request(req)
puts回应#{res.code}#{res.message}:#{res.body}


How can I make a Https post with a header in Ruby with a json?

I have tried:

uri = URI.parse("https://...")
    https = Net::HTTP.new(uri.host,uri.port)
    req = Net::HTTP::Post.new(uri.path)
    req['foo'] = bar
    res = https.request(req)
puts res.body

解决方案

The problem it was a json. This solve my problem. Anyway, my question was not clear, so the bounty goes to Juri

require 'uri'
require 'net/http'
require 'net/https'
require 'json'

@toSend = {
    "date" => "2012-07-02",
    "aaaa" => "bbbbb",
    "cccc" => "dddd"
}.to_json

uri = URI.parse("https:/...")
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
req['foo'] = 'bar'
req.body = "[ #{@toSend} ]"
res = https.request(req)
puts "Response #{res.code} #{res.message}: #{res.body}"

这篇关于带有标头的Ruby https POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆