React Native--請求Web端(Java)網(wǎng)絡數(shù)據(jù)

1.在RN中使用fetch請求外部數(shù)據(jù)


fetch請求

//請求參數(shù)

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接收參數(shù)

2.1 pom.xml文件中引包


pom.xml引包

2.2 application.xml配置文件中添加


配置上傳文件

2.3 Action中獲取參數(shù)

HttpServletRequest request = ServletActionContext.getRequest();

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

或者是controller中:

@ResponseBody

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

public String getMonery(String username,String password) {

return "";

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容