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

2016-11-11  本文已影响0人  AmyConan

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 "";

}

上一篇下一篇

猜你喜欢

热点阅读