打开studio在左侧列表中找到config.xml文件,双击打开,选择插件选项勾选cordova-plugin-http文件,并在权限选项中选择相关权限。最后保存文件。

网络请求

summer框架中的联系可以使用cordova插件(cordova-plugin-http),主要功能包含:

1、get请求数据

  1. cordovaHTTP.get("http://opentest.yonyoutelecom.cn/mobile/isvName.do?account=qinfx&q=",//请求的url地址
  2. { //请求的数据
  3. a: 1,
  4. b: 2
  5. }, {Authorization: "OAuth2: token"},//
  6. function (response) {//成功的回调
  7. // prints 200
  8. alert(response.status);
  9. try {
  10. response.data = JSON.parse(response.data);
  11. // prints test
  12. $summer.alert(response.data);
  13. } catch (e) {
  14. alert("JSON parsing error");
  15. }
  16. }, function (response) {//失败的回调
  17. // prints 403
  18. alert(response.status);
  19. //prints Permission denied
  20. alert(response.error);
  21. }

2、post请求数据

  1. cordovaHTTP.post("http://opentest.yonyoutelecom.cn/mobile/isvName.do?account=qinfx&q=",//请求的url地址
  2. {//请求的数据
  3. a: 1,
  4. b: 2
  5. }, {Authorization: "OAuth2: token"},
  6. function (response) {//成功的回调
  7. // prints 200
  8. alert(response.status);
  9. try {
  10. response.data = JSON.parse(response.data);
  11. // prints test
  12. $summer.alert(response.data);
  13. } catch (e) {
  14. alert("JSON parsing error");
  15. }
  16. }, function (response) {//失败的回调
  17. // prints 403
  18. alert(response.status);
  19. //prints Permission denied
  20. alert(response.error);
  21. }

用例github下载地

更多参见

文档更新时间: 2018-01-15 13:53