一、项目、作者何许人也
httpbin是大神kennethreitz为搭建测试用的http服务而写的项目,httpbin 这个服务应用能测试HTTP请求及响应的各种信息,比如 cookie、ip、headers 和登录验证等,且支持 GET、POST 等多种方法,对 web 开发和测试具有很大的帮助,它是用 Python + Flask 编写的,是一个开源项目。
Kenneth Reitz: 著名的python首席架构师,requests、python-guide、pipenv、legit、autoenv等一系列大名鼎鼎的python类库及工具的创作者,大神级程序员,据说其身价高达5亿美元。
二、观摩庐山真面目
http方法组展开的接口
其他的分组
点击 HTML form 是一个form表单提交页面,可以用来测试
三、怎么玩
以get请求为例:
展开 HTTP Methods 方法下面的get请求,选择Try it out,
出现 Execute 点击他, Response body 返回json数据。
依次类推,post请求返回数据如下:
包含form表单、json数据、header、url、origin 等信息。
四、后端怎么调用
1. RestTemplate测试代码
这里选取了四个典型场景: get请求、formdata表单提交、json字符串post提交、带文件 multipart/form-data 提交
import java.util.Arrays;
import org.apache.commons.lang3.RandomUtils;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class RestTemplateSimpleTest
{
private static RestTemplate restTemplate;
static
{
int type = RandomUtils.nextInt(1, 5);
log.info("--------- type:{}", type);
switch (type)
{
case 1:
// 使用默认客户端构造RestTemplate,写法1
/*** Java HttpURLConnection (默认RestTemplate采用,不支持HTTP2) ***/
restTemplate =