猿问

如何使用poster进行接口测试

如何使用poster进行接口测试


偶然的你
浏览 838回答 1
1回答

小唯快跑啊

import java.io.InputStream;import java.util.HashMap;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.commons.io.IOUtils;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;@Controllerpublic class TestController {@RequestMapping(produces="text/plain;charset=UTF-8",value = "print")@ResponseBodypublic String print(HttpServletRequest request, HttpServletResponse response) throws Exception {Map<String, Object> map = new HashMap<String, Object>();try {InputStream inputStream = request.getInputStream();byte[] bytes = IOUtils.toByteArray(inputStream);String result = new String(bytes, "UTF-8");// System.out.println(result);JSONObject json = (JSONObject) JSONObject.parse(result);String name = json.getString("username");if (name.equals("aaa")) {map.put("us", "success");} else {map.put("us", "fail");}// System.err.println(name);} catch (Exception e) {e.printStackTrace();}return JSON.toJSONString(map);}}
随时随地看视频慕课网APP
我要回答