【发布时间】:2016-03-20 00:16:56
【问题描述】:
我想从 iMacro 内部到 API 端点执行 HTTP POST。实际上,类似于以下内容:
curl -d "data=foo" http://example.com/API
在 iMacros 中,它可能看起来像这样:
我的 imacro.iimVERSION BUILD=10.4.28.1074
TAB T=1
URL GOTO=javascript:post('http://example.com/API', {data: 'foo'});
function post(path, params, method) {
// Reference: http://stackoverflow.com/a/133997/1640892
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
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);
}
}
document.body.appendChild(form);
form.submit();
}
但上述方法似乎是一个漫长而困难的方法。如果它甚至可以工作。
是否有更短、更直接或更有效的解决方案?
【问题讨论】:
-
也许是
XMLHttpRequest()而不是function post()?