美文网首页
React Native--请求Web端(Java)网络数据

React Native--请求Web端(Java)网络数据

作者: AmyConan | 来源:发表于2016-11-11 13:59 被阅读0次

    1.在RN中使用fetch请求外部数据


    fetch请求

    //请求参数

    letformData=newFormData();

    formData.append("username",this.userName);

    formData.append("password",this.password);

    //请求URL

    leturl="http://172.16.0.236:8080/zt";

    //let url = "http://172.16.0.236:8080/SpringMVC-Demo/app/loginApp";

    varfetchOptions= {

    method:'POST',

    headers: {

    'Accept':'application/json',

    'Content-Type':'multipart/form-data;boundary=6ff46e0b6b5148d984f148b6542e5a5d'

    },

    body:data

    };

    fetch(url,fetchOptions)

    .then((response) => response.text())

    .then((responseText) => {

    alert(responseText);

    }).done();

    2.Web端用Java接收参数

    2.1 pom.xml文件中引包


    pom.xml引包

    2.2 application.xml配置文件中添加

    配置上传文件

    2.3 Action中获取参数

    HttpServletRequest request = ServletActionContext.getRequest();

    System.out.println("====="+request.getParameter("password"));

    或者是controller中:

    @ResponseBody

    @RequestMapping(value = "/app/loginApp")

    public String getMonery(String username,String password) {

    return "";

    }

    相关文章

      网友评论

          本文标题:React Native--请求Web端(Java)网络数据

          本文链接:https://www.haomeiwen.com/subject/kbrfpttx.html