日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

http接口测试工具——RESTClient

發(fā)布時間:2025/3/20 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 http接口测试工具——RESTClient 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標準>>>

WizTools.org RESTClient?is a Java Swing application for testing RESTful web services. It might be used for testing other HTTP communications too. This is a short introduction of this tool explaining its various features.

The First Step

RESTClient can be downloaded from?http://code.google.com/p/rest-client/downloads/list. It is a single Jar file. To run it, you need to have Java 5 installed. After downloading, Windows users need to double-click to start the application. Non-Windows users, fire up your command prompt/shell, and issue:

$ java -jar restclient-2.1-jar-with-dependencies.jar

The UI

Once it is started, you will see this UI:

As seen in the screenshot, the UI is divided into two sections. The top portion has the HTTP request details and the bottom portion has the HTTP response details. To get started, just enter the value “http://wiztools.org/” in the URL field. Now press the green “>>” button near to the URL field. You should find the response details in the Response section of the UI.

RESTful Web services Example

Now we will use RESTClient to learn how it can be used to test a RESTful web services. We will take the example of social bookmarking site?BibSonomy.org?for example. If you do not have an account with this site, please sign up for a free account. The REST API of this service is documented in this page:?http://www.bibsonomy.org/help/doc/api.html. For using this service, you have to request API key here:?http://www.bibsonomy.org/help/doc/gettingaccess.html.

Once you get the API key, you are ready to start! Fire up RESTClient. We will do the following operations on BibSonomy.org:

  • List all the posts you made

  • Create a post (bookmark entry)

  • Change post

  • Delete post

  • Before we start trying out the features of BibSonomy.org, you have to understand the authentication mechanism of this site. In the authentication tab, make sure you give:

    • BASIC authentication method should be selected.

    • Preemptive can be selected (not mandatory). Having this selected will send the authentication details to the server even before the server challenges for it.

    • Give your BibSonomy username and API key as the password.

    Now we jump on to the operations. All the operations will require that this authentication detail to be configured.

    Operation 1: List all the posts you made

    To list all the posts you have made, enter this URL in the URL box:

    http://www.bibsonomy.org/api/posts?user=subwiz&resourcetype=bookmark

    (Note: Replace all mentions of `subwiz' with your BibSonomy.org userid. `subwiz' is the author's BibSonomy.org userid.)

    Make sure you have entered the authentication details as mentioned. Now with the method entered as GET, hit the green “>>” button.


    As you see in the body tab of the Response section, it has returned an XML saying that this user does not have any posts yet. We will be using?Operation 1?further down in the tutorial to see the status of our additions, updations and deletions.

    Operation 2: Create a post

    To create a post, you have to hit this URL:

    http://www.bibsonomy.org/api/users/subwiz/posts

    The HTTP method to be used is POST for create operation. Make sure you select this option in the Method tab.


    After selecting the POST method, the Body tab controls get enabled. Body is supported only for POST and PUT methods. In the Body tab, add the bookmark post detail in the following format:

    <?xml?version="1.0"?> <bibsonomy><post?description="WizTools.org?OpenSource"><user?name="subwiz"/><tag?name="opensource"/><tag?name="java"/><group?name="public"/><bookmark?url="http://wiztools.org/"?title="WizTools.org"/></post> </bibsonomy>

    Make sure you change the content-type to?application/xml?and charset to?UTF-8?(click the Edit button near to the content-type/charset text field to change). Finally, it should look like:

    Now execute the request by pressing the “>>” button. The response screen should be something similar to:


    and:


    Response status 201 means success. Make note of the hash returned (which in our case is: 03fb1f5d1634e4bd72e6ccdc0cdafcc2) in the body of the response. This will be needed for the next operation. Now perform?Operation 1?to see your new post getting displayed.

    Operation 3: Change post

    The URL for updating a existing post is:

    http://www.bibsonomy.org/api/users/subwiz/posts/03fb1f5d1634e4bd72e6ccdc0cdafcc2

    For updating a post with new/changed data, HTTP PUT method is used. Select PUT from the Methods tab, and enter in the body text:

    <?xml?version="1.0"?> <bibsonomy><post?description="WizTools.org?OpenSource"><user?name="subwiz"/><tag?name="opensource"/><tag?name="java"/><tag?name="REST"/><bookmark?url="http://wiztools.org/"?title="WizTools.org--OpenSource?Software"?intrahash="03fb1f5d1634e4bd72e6ccdc0cdafcc2"interhash="03fb1f5d1634e4bd72e6ccdc0cdafcc2"/></post> </bibsonomy>

    As you see, we have added a new tag REST and updated the title. Also remember to set the Content-type and charset to?application/xml?and?UTF-8?respectively. Execute the request, and performOperation 1?to validate.

    Operation 4: Delete post

    The final operation is the DELETE operation. The URL for this is:

    http://www.bibsonomy.org/api/users/subwiz/posts/03fb1f5d1634e4bd72e6ccdc0cdafcc2

    From the Methods tab, select DELETE. If the DELETE operation is successful, the Response status code will be 200 OK. Perform?Operation 1?to validate.

    Testing Using RESTClient

    Another interesting feature in RESTClient is the ability to attach test scripts written in Groovy with each request. More on this is covered in the?tutorial at the site.

    Persisting Request et all

    RESTClient also supports persisting request, response and request-response combination. This helps in record and playback support. These options are available in the?File?menu.

    What Else?

    RESTClient has been developed with active input from the?REST-Discuss?community. If you have any request (both bugs and features), just?file a issue.

    Topics:

    ?


    轉載于:https://my.oschina.net/hellotest/blog/609422

    總結

    以上是生活随笔為你收集整理的http接口测试工具——RESTClient的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。