【问题标题】:cordova.advanced.http post request is not workingcordova.advanced.http 发布请求不起作用
【发布时间】:2020-09-28 17:52:47
【问题描述】:

我正在尝试将我的后端连接到一个 Cordova 应用程序,并且我正处于开发的早期阶段,所以我只是尝试在浏览器中对其进行测试。我无法让发布请求正常工作,或者 api 调用事实,我的 url(我为帖子更改了它)是正确的,因为我可以通过邮递员点击它并在外部服务器上运行,我使用的是 cordova 插件: 科尔多瓦-高级-http

const button = document.getElementById('loginButton');

button.addEventListener('click', login);
function login() {
    const options = {
        method: 'post',
        data: { email: "mud@water.sand", password: "P@ssw0rd"},
        headers: { Authorization: 'Bearer Token: token' }
    };
    console.log(options);
    cordova.plugin.http.sendRequest('http://oa.com:8080/user/login/', options, function(response) {
        // prints 200
        console.log(response.status);
        console.log(response.data.token);
    }, function(response) {
        // prints 403
        console.log(response.status);
        //prints Permission denied
        console.log(response.error);
    });
}

【问题讨论】:

    标签: android html node.js api cordova


    【解决方案1】:

    我想通了,在我的 html 中,我在提交时执行我的脚本,而在我的脚本中,我将它定义为在按钮上执行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 2019-01-27
      • 2017-01-28
      • 2017-08-20
      • 1970-01-01
      相关资源
      最近更新 更多