为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用poster进行接口测试

如何使用poster进行接口测试

偶然的你 2018-11-26 04:00:04
如何使用poster进行接口测试
查看完整描述

1 回答

?
小唯快跑啊

TA贡献1863条经验 获得超2个赞


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;

@Controller
public class TestController {
@RequestMapping(produces="text/plain;charset=UTF-8",value = "print")
@ResponseBody
public 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);
}
}



查看完整回答
反对 回复 2018-12-20
  • 1 回答
  • 0 关注
  • 772 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信