如何调试/显示使用RestClient发送的请求 [英] How to debug/display request sent using RestClient

查看:1266
本文介绍了如何调试/显示使用RestClient发送的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用RestClient使用post方法访问web服务。我正在发送指定的授权令牌,但我仍然收到403状态错误,这意味着我被禁止使用该api。有什么方法可以看到使用http post发送的请求,以便我可以验证标头?我无法找到任何示例或任何文档提及如何做到这一点?

I am trying to use RestClient to access a webservice using post method. I am sending the authorization token as specified but I am still getting a 403 status error which means I am forbidden to use that api. Is there any way that I can see the request being sent with http post so that I can verify the headers? I am not able to find any example or any documentation which mentions as to how to do that?

我的代码与此类似:

token = get_token

response = RestClient.post "https://api-dev.xxx.com/software/services/search/ABC",
  :authorization => "Bearer #{token}"


推荐答案

您可以尝试启用 RestClient 的日志记录,看看它是否提供了任何有用的输出:

You could try enabling RestClient's logging and see whether this provides any useful output:

RESTCLIENT_LOG=stdout path/to/my/program

或者如果你使用的是Rails

or if you are using Rails

RESTCLIENT_LOG=stdout bundle exec passenger

用您选择的服务器替换乘客。这会将所有日志记录重定向到标准输出(您的控制台)。

replacing passenger with your choice of server. This will redirect all logging to standard output (your console).

我个人更喜欢在需要检查或排除HTTP请求时使用更详细的工具。

Personally I prefer using more verbose tools when I need to inspect or troubleshoot HTTP requests.

如果您愿意,可以尝试 curl wget 命令行,或允许您轻松执行请求的许多浏览器扩展之一,检查输出,保存以供将来使用,设置不同的环境等。 Postman 进阶REST客户端是不错的选择。

You could try curl or wget if you prefer command-line, or one of the many browser extensions which let you perform requests easily, inspect output, save for future use, set up different environments etc. Both Postman and Advanced REST Client are good choices.

这篇关于如何调试/显示使用RestClient发送的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆