在 RESTful Web 服务上测试 PUT 方法
我有一个简单的 RESTful Web 服务,我希望在某个资源上测试 PUT 方法。我想以最简单的方式使用尽可能少的附加工具来完成此操作。
例如,测试资源的 GET 方法非常简单 - 只需在浏览器中访问资源 URL 即可。我知道在测试 PUT 方法时不可能达到相同的简单程度。
以下两个假设应该可以简化该任务:
- 请求正文是预先准备好的 json 字符串。这意味着,无论我的问题的解决方案是什么,它都不必根据用户输入组成 json 字符串 - 用户输入是最终的 json 字符串。
- 我使用的 REST 引擎 (OpenRasta) 可以理解某些 URL 装饰器,这些装饰器告诉它所需的 HTTP 方法是什么。因此,我可以发出 POST 请求,该请求在 REST 引擎内将被视为 PUT 请求。这意味着,可以使用常规 html 表单来测试 PUT 操作。
但是,我希望用户能够输入要放入的资源的 URL,这会使任务更加复杂,但会简化测试。
提前感谢所有好心人。
PS
我既没有安装 PHP 也没有安装 PERL,但我有 python。然而,如果可能的话,留在 javascript 领域似乎是最简单的方法。我的操作系统是 Windows,如果这很重要的话。
I have a simple RESTful web service and I wish to test the PUT method on a certain resource. I would like to do it in the most simple way using as few additional tools as possible.
For instance, testing the GET method of a resource is the peak of simplicity - just going to the resource URL in the browser. I understand that it is impossible to reach the same level of simplicity when testing a PUT method.
The following two assumptions should ease the task:
- The request body is a json string prepared beforehand. Meaning, whatever is the solution to my problem it does not have to compose a json string from the user input - the user input is the final json string.
- The REST engine I use (OpenRasta) understands certain URL decorators, which tell it what is the desired HTTP method. Hence I can issue a POST request, which would be treated as a PUT request inside the REST engine. This means, regular html form can be used to test the PUT action.
However, I wish the user to be able to enter the URL of the resource to be PUT to, which makes the task more complicated, but eases the testing.
Thanks to all the good samaritans out there in advance.
P.S.
I have neither PHP nor PERL installed, but I do have python. However, staying within the realm of javascript seems to be the simplest approach, if possible. My OS is Windows, if that matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用 Firefox 的 Poster 插件。您可以在这里。
I'd suggest using the Poster add-on for Firefox. You can find it over here.
除了提供检查来自桌面和 Web 应用程序的 HTTP 请求的方法之外,Fiddler 还允许您创建任意 HTTP 请求(以及重新发送应用程序先前发送的内容)。
它与浏览器无关。
As well as providing a means to inspect HTTP requests coming from desktop and web applications, Fiddler allows you to create arbitrary HTTP requests (as well as resend ones that were previously sent by an application).
It is browser-agnostic.
我使用 RESTClient firefox 插件(您不能使用 URL消息正文,但至少您可以保存您的请求),但也建议在命令行上使用 curl 。
也许您还应该看看这个 SO问题。
I use the RESTClient firefox plugin (you can not use an URL for the message body but at least you can save your request) but also would recommend curl on the command line.
Maybe you should also have a look at this SO question.