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

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

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容