使用 WebMock 存根 HTTPS 调用 [英] Stubing HTTPS call using WebMock
问题描述
我想使用 webmock
存根 https
调用.让我们假设网关 url 为 https://some_gateway.com
.
I'd like to stub https
call using webmock
.
Let's assume gateway url as https://some_gateway.com
.
做完之后:
stub_request(:post, 'https://some_gateway.com').with(body: {})
在规格中.
我使用 Net::HTTP 生成请求:
I use Net::HTTP to generate request:
Net::HTTP.post_form(URI.parse('https://some_gateway.com'), {})
我收到问题,因为 Webmock 需要 https://some_gateway.com
但收到添加端口 433 的版本,所以:http://www.secure.fake-payment.com:443/gateway_prod
所以看不到注册存根.
I receive problem because Webmock expects https://some_gateway.com
but receives version with added port 433 so: http://www.secure.fake-payment.com:443/gateway_prod
so can't see registered stub.
我该如何处理这种行为?
How can I deal with this behavior ?
推荐答案
看看这个问题的答案:WebMock: Rspec - 使用 JSON 响应测试 Facebook 验证
您的代码将使用端口 443 执行 http
请求,而不是真正执行 https
Your code will do http
request with port 443 vs doing really https
Net::HTTP.post_form(URI.parse('https://some_gateway.com'), {})
在这里您可以找到如何使用 Net::HTTP 执行 https
请求的答案使用 Net::HTTP.get 获取 https 网址
And here you can find the answer how to do https
request using Net::HTTP
Using Net::HTTP.get for an https url
这篇关于使用 WebMock 存根 HTTPS 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!