使用Ruby-curl检索完整的请求字符串
我打算发送如下请求:使用Ruby-curl检索完整的请求字符串,ruby,curb,Ruby,Curb,我打算发送如下请求: c = Curl::Easy.http_post("https://example.com", json_string ) do |curl| curl.headers['Accept'] = 'application/json' curl.headers['Content-Type'] = 'application/json' curl.headers['Api-Version'] = '2.2' end 我想记
c = Curl::Easy.http_post("https://example.com", json_string
) do |curl|
curl.headers['Accept'] = 'application/json'
curl.headers['Content-Type'] = 'application/json'
curl.headers['Api-Version'] = '2.2'
end
我想记录正在发出的确切http请求。有没有办法获取实际请求(基本路径、查询参数、标题和正文)?以前对我有帮助。在您的示例中,您可以尝试:
curl.on_debug do |type, data|
puts type, data
end
您可以通过不同的方式获得解决方案: 在您的区块内,您可以放置:
curl.verbose = true # that prints a detailed output of the connection
或在街区外:
c.url # return the url with queries
c.total_time # retrieve the total time for the prev transfer (name resolving, TCP,...)
c.header_str # return the response header
c.headers # return your call header
c.body_str # return the body of the response
在调用这些方法之前,请记住调用c.perform(如果尚未执行)
在这里可以找到更多选项:您是否尝试在块内设置
curl.verbose=true
?