postman的下载
官网:https://www.getpostman.com/downloads/
国产的软件:postman 也是不错的选择。
https://apifox.com/compare/postman-vs-apifox/?utm_source=baidu&utm_medium=sem&utm_campaign=251430232&utm_content=7810722126&utm_term=postman%E5%9C%A8%E7%BA%BF%E8%B0%83%E8%AF%95&bd_vid=12479242396271193667
创建账号或者用谷歌浏览器账号登录
一个demo了解一下
我做的是一个app,后台使用java做的,app通过ajax来请求后台,但是我不知道后台有没有请求成功!
因此需要一个测试接口的东西测试我做的接口有没有问题
我的app里面的ajax是这样写的
api.ajax({
url: ‘http://192.168.0.107:8080/jiekou/RegeditServlet’,
method: ‘get’,
dataType:’JSON’,
returnAll:true,
timeout:30,
data: {
values: {
name: user,
pass: ps
}
}
},function(ret, err){
if (ret) {
api.alert( JSON.stringify( ret ) );
} else {
api.alert(JSON.stringify( err ) );
}
});
请求方式是get post什么的,根据自己的需求选
url就是自己请求后台的路径
key是属性名 value是属性值都和后台要接收都属性名一致
附上我的java后台接收的servlet的代码,方便理解postman的流程
package cn.com.servlet;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.com.bean.User;
import net.sf.json.JSONArray;
public class RegeditServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//ServletContext ser = getServletContext();
//ApplicationContext ioc = (ApplicationContext) ser.getAttribute(“app”);
doPost(request, response);
//Regedit re=ioc.getBean(Regedit.class);
//re.login();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding(“utf-8”);
String user=request.getParameter(“name”);
String pass=request.getParameter(“pass”);
System.out.println(“用户名:”+user);
System.out.println(“密码:”+pass);
//将List转化为JSON
System.out.println(“———-“);
String ty=”java与apicloud的前后台交互!!”;
ArrayList<String> list=new ArrayList<String>();
list.add(ty);
JSONArray json=JSONArray.fromObject(list);
//设置编码
response.setCharacterEncoding(“utf-8”);
//写入到前台
response.getWriter().write(json.toString());
}
}
然后点击send,就会返回java后台给前台页面传递的数据
有返回值,说明这个接口没有问题