Ruby中的HTTP.post_form,带有自定义标头 [英] HTTP.post_form in Ruby with custom headers
本文介绍了Ruby中的HTTP.post_form,带有自定义标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用Nets / HTTP来使用 POST
并输入自定义用户代理。我通常使用 open-uri
但它不能 POST
可以吗?
Im trying to use Nets/HTTP to use POST
and put in a custom user agent. I've typically used open-uri
but it cant do POST
can it?
我使用
resp, data = Net::HTTP.post_form(url, query)
如何更改此选项以自定义标题?
How would I change this to throw custom headers in?
编辑我的查询是:
query = {'a'=>'b'}
推荐答案
你可以试试这个,例如:
You can try this, for example:
http = Net::HTTP.new('domain.com', 80)
path = '/url'
data = 'form=data&more=values'
headers = {
'Cookie' => cookie,
'Content-Type' => 'application/x-www-form-urlencoded'
}
resp, data = http.post(path, data, headers)
这篇关于Ruby中的HTTP.post_form,带有自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文