首页 > 解决方案 > 如何从 expressjs 服务器发送 xhttp 请求?

问题描述

我正在尝试从我的后端向linkedin 服务发送一个发布请求。

exports.GetAccessToken = function (req, res) {
var xhttp = new XMLHttpRequest();
var decoded = jwt.verify(req.query.jwt_token, MariaDB_config.PUB_key);
xhttp.onreadystatechange = function () { // handle request response
  if (this.readyState === 4 && this.status === 200) {
    console.log("answer : " + this.responseText);
  }
};
xhttp.handleError()
// Send a post request
xhttp.open("POST", "https://www.linkedin.com/oauth/v2/accessToken?code=" + decoded.code + "privatestuff", true);
xhttp.send();
}

我得到以下错误:

TypeError:无法读取未定义的属性“堆栈”

到目前为止,这种方法运行良好。

标签: javascriptnode.jsexpresspost

解决方案


我错误地使用了“xhttp.handleError()”,我删除了它,现在它可以正常工作了。


推荐阅读