iMacros Http POST到API端点 [英] iMacros Http POST to API endpoint
问题描述
我想从iMacro内部到API端点执行 HTTP POST
。实际上,如下所示:
I want to do an HTTP POST
from inside an iMacro to an API endpoint. Effectively, something like the following:
curl -d "data=foo" http://example.com/API
在iMacros中,它可能如下所示:
In iMacros, it might look something like this:
VERSION 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();
}
但上述似乎是一个漫长而艰难的方法。如果它甚至可以工作。
But the above seems like a long and difficult way to do this. If it even works.
是否有更短,更直接或更有效的解决方案?
Is there a shorter, more direct or efficient solution?
推荐答案
您可以使用javascript和 http://wiki.imacros.net/iMacros_for_Firefox jQuery的。然后用任何形式,获取和发布请求的东西都很容易。
You can use http://wiki.imacros.net/iMacros_for_Firefox with javascript and jquery. Then it's easy with any form, get and post request thing.
使用javascript和imacros for firefox的小javascript示例:
Small javascript example with jquery and imacros for firefox:
function loadScriptFromURL(url) {
var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
async = false;
request.open('GET', url, async);
request.send();
if (request.status !== 200) {
var message = 'an error occurred while loading script at url: ' + url + ', status: ' + request.status;
iimDisplay(message);
return false;
}
eval(request.response);
return true;
}
loadScriptFromURL('https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js');
$ = window.$,
JQuery = window.JQuery;
这篇关于iMacros Http POST到API端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!