Android AndBase框架使用封装好的函数完成Http请求(三)

2019-12-10 18:34:49刘景俊

2.使用AndBase框架实现有参Http Post请求 

其实调用的方式都是相同的,,只不过Post请求需要传递相关的参数...使用有参的Post请求...这里是向一个JSP传递相关参数来完成数据信息的验证...

public void PostClick(View v){
 url="http://www.easck.com/JSP/post.jsp";
 params=new AbRequestParams();
 params.put("name", "darker");
 params.put("password", "49681888");
 httpUtil.post(url, params, new PostResponseListener(this));
}

  这里我就不粘贴PostResponseListener的代码了...贴一下JSP页面的代码..相关的JSP代码如下...这里的JSP代码非常的简单..并且前面在使用Volley的时候也使用过..JSP页面我们完全可以自己书写的更加复杂一些,那么就能够实现更多的功能...

<%
 String name=request.getParameter("name");
 String password=request.getParameter("password");
 if("darker".equals(name)&& "49681888".equals(password)){
  out.println("Receive name is:"+name);
 out.println("Receive password is:"+password);%>
 Your Message are right!
 <%}else{
  out.println("Receive name is:"+name);
 out.println("Receive password is:"+password);%>
 Your Message are wrong!
 <%}%> 

3.使用AndBase框架实现有参Http Get请求

  有参的Get请求一般用于文件,数据资源的上传...将上传的资源以及名称作为参数传递给服务器..这里不涉及安全上的问题..因此可以使用带有参数的Get请求...这里向服务器上传文件..需要添加相关参数...

public void FileLoadClick(View v){
  url="http://www.easck.com/download/cache_files/aa.txt");
  params.put(file1.getName(),file1);
  
  getView();
  httpUtil.get(url, params, new FileSendResponseListener(this, this, v, max_tv, num_tv, progressBar));
 }