Testing of rest services based on SPRINGMVC and restclient

Source: Internet
Author: User

In the development, not familiar with the driver-driven test development coder often like to start the service application after the test, for GET request can be directly in the browser input URL can be, parameter non-Chinese can be directly appended to the URL. However, testing for other requests must be done with the appropriate controls, such as a restful architecture.

The SPRINGMVC framework is part of the spring framework and provides good support for restful. SPRINGMVC can accept JSON-type data, or convert entities to JSON to return to the client. Restclient is a plug-in for an HTTP request from Mozilla Firefox, which can select the request method, specify the request header, and add the request body.

The completion of the HTPP request can be delineated as three parts from the data's point of view: Data Issuance--"data processing--" returns. This article mainly discusses HTTP parameter mappings based on SPRINGMVC and restclient controls.

Using the browser directly to enter the URL link, SPRINGMVC controller can directly accept the corresponding request parameter values,

The browser operates as follows:

Notice that the HTTP request Content-type is application/xhtml+xml, if you set the Content-type of the request header to a different value will it normally accept?

Create a new Post request processing method, two parameters, at this time through the Restclient issued a request as follows:

The background output is as follows:

This shows that the background does not accept the age parameter data. Now change the request header as follows

Request response status is 200ok, view background output:

Normal output in the background.

Summarize:

When using Restclient for request testing, if the background cannot accept parameter data, the configuration of the request header should be checked.

Testing of rest services based on SPRINGMVC and restclient

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.