模仿Http请求和响应:MockServer
jopen
11年前
MockServer是一个API能够模仿任何通过HTTP连接的服务器或服务,如REST 或 RPC service。提供Java和JavaScript两种API。
Requests 可匹配于:
- path (regex or plain text)
- body (regex or plain text)
- headers
- cookies
- query parameters (GET)
- body parameters (POST)
Responses 可包含:
- status code
- body
- headers
- cookies
示例:
HttpResponse httpResponse = new HttpResponse().withStatusCode(200) .withHeaders( new Header("Content-Type", "application/json; charset=utf-8"), new Header("Cache-Control", "public, max-age=86400") ) .withBody("{ message: 'a simple json response' }");