新手问题 求解带 HTTP 头的 POST REQUEST 该怎么实现

netuser · 2015年03月13日 · 最后由 netuser 回复于 2015年03月13日 · 2657 次阅读

需要提交的 HTTP 头是这样的, { "X-Requested-With:" => 'XMLHttpRequest', "Cookie:" => cookie, "Referer:" => "http://refer" } 尝试用了几种办法,都失败了 比如

uri = URI.parse("http://")
http = Net::HTTP.new(uri.host, uri.port)
response = http.post uri, post_data, header
uri = URI.parse("http://")
http = Net::HTTP.new(uri.host, uri.port)

request = Net::HTTP::Post.new(uri.request_uri)

request.set_form_data(post_data)

request.initialize_http_header(header)

response = http.request(request)

没什么说的,看文档啊!

另,"X-Requested-With:" => 'XMLHttpRequest',冒号要去掉

我这么写的。

uri = URI.parse("https://cn.avoscloud.com/1.1/push")
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
test = Net::HTTP::Post.new(uri.path)
test.body = content.to_json
test["X-AVOSCloud-Application-Id"] = ''
test["X-AVOSCloud-Application-Key"] = ''
test["Content-Type"] = "application/json" 
res = https.request(test)

#1 楼 @hooooopo 3Q3Q3Q 没想到会是这个原因! 对于一个新手来说。。。想找到适合的文档好难

有一个新问题,POST 的返回值是 GB2312 编码,如何转换为 GB2312 呢

需要 登录 后方可回复, 如果你还没有账号请 注册新账号