我正在开发Office Web加载项。当我使用以下功能从Home.js使用POST调用来调用外部API时,即使方法是POST,它也会在从浏览器离开时自动转换为GET(在服务器端也会收到GET请求)。使用POST方法发布数据?
详细信息: 加载项开发环境:Visual Studio 2017
function post(path, params) {
var method = "POST";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path); //path is HTTPS
form.setAttribute("enctype", "multipart/form-data");
form.setAttribute("target", "_blank");
for (var key in params) {
if (params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
console.log(form);
document.body.appendChild(form);
form.submit();
}