【发布时间】:2018-03-08 14:30:26
【问题描述】:
我使用此代码发出网络请求:
request = HTTPClient.new()
request.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
request.set_auth(url, terminal['api_login'], terminal['api_password'])
response = request.post(url, request_body, {"Content-Type" => "application/xml", "cache-control" => "no-cache"}).body
但是当我尝试使用存根请求实现 rspec 时,添加了两个参数,它们在每个测试环境中每次都不同:
stub_request(:post, "http://www.example.com/").
with(:headers => {'Accept'=>'*/*', 'Cache-Control'=>'no-cache', 'Content-Type'=>'application/xml', 'Date'=>'Thu, 08 Mar 2018 14:20:55 GMT', 'User-Agent'=>'HTTPClient/1.0 (2.8.3, ruby 2.2.2 (2015-04-13))'}).
to_return(:status => 200, :body => "", :headers => {})
如何配置 http 客户端不发送 Date 并让 User-Agent 发送像“Ruby”这样简单的东西?
是否可以配置这些参数?
【问题讨论】: