我需要在一个遗留系统上执行一个非常特定的请求,并发现在get请求期间,http库正在将任何%2C
改回,
。使用不同实现的net-http、httparty、faraday和open-uri也存在同样的问题。
2.5.0 :001 > require 'net/http'
=> true
2.5.0 :002 > require 'erb'
=> true
2.5.0 :003 > link = "http://example.com?q=" + ERB::Util.url_encode("Hello, World")
=> "http://example.com?q=Hello%2C%20World"
2.5.0 :004 > uri = URI(link)
=> #<URI::HTTP http://example.com?q=Hello%2C%20World>
2.5.0 :005 > res = Net::HTTP.get_response(uri)
=> #<Net::HTTPOK 200 OK readbody=true>
在我使用VCR查看实际请求之前,所有这些看起来都很好
http_interactions:
- request:
method: get
uri: http://example.com/?q=Hello,%20World
body:
encoding: US-ASCII
string: ''
...
如何将请求保持为http://example.com?q=Hello%2C%20World
https://stackoverflow.com/questions/50708934
复制相似问题