使用 http 对象发送 HTTP 请求,参数表与返回值与 http.* 处理器一致
约定
/data/app
, 实际编写时需替换为应用根目录。<>
标识自行替换的内容。 例如: icon-<图标名称>
, 实际编写时应替换为: icon-foo
, icon-bar
...示例
System
/data/app/scripts/test.js
function HttpTest() {// Gethttp.Get("http://127.0.0.1/get?foo=bar");http.Get("http://127.0.0.1/get?foo=bar", { hello: "world" });http.Get("http://127.0.0.1/get?foo=bar",{ hello: "world" },{ Auth: "Test" });// Posthttp.Post("http://127.0.0.1/path?foo=bar");http.Post("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Post("http://127.0.0.1/path?foo=bar", { name: "Lucy" }, null, {hello: "world",});http.Post("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },null,{ hello: "world" },{ Auth: "Test" });// Post File via payload 文件路径为相对路径 相对地址, 示例: `/text/foo.txt`, 绝对路径为: `/data/app/data/text/foo.txt`。http.Post("http://127.0.0.1/path?foo=bar", "/path/root/file");// Post File via fileshttp.Post("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ f1: "/path/root/f1", f2: "/path/root/f2" });// Patchhttp.Patch("http://127.0.0.1/path?foo=bar");http.Patch("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Patch("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Patch("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });// Puthttp.Put("http://127.0.0.1/path?foo=bar");http.Put("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Put("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Put("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });// Deletehttp.Delete("http://127.0.0.1/path?foo=bar");http.Delete("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Delete("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Delete("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });// Headhttp.Head("http://127.0.0.1/path?foo=bar");http.Head("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Head("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Head("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });// Sendhttp.Send("POST", "http://127.0.0.1/path?foo=bar");http.Send("POST", "http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Send("POST","http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Send("POST","http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });}
使用 http 对象发送 HTTP 请求,参数表与返回值与 http.* 处理器一致
约定
/data/app
, 实际编写时需替换为应用根目录。<>
标识自行替换的内容。 例如: icon-<图标名称>
, 实际编写时应替换为: icon-foo
, icon-bar
...示例
System
/data/app/scripts/test.js
function HttpTest() {// Gethttp.Get("http://127.0.0.1/get?foo=bar");http.Get("http://127.0.0.1/get?foo=bar", { hello: "world" });http.Get("http://127.0.0.1/get?foo=bar",{ hello: "world" },{ Auth: "Test" });// Posthttp.Post("http://127.0.0.1/path?foo=bar");http.Post("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Post("http://127.0.0.1/path?foo=bar", { name: "Lucy" }, null, {hello: "world",});http.Post("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },null,{ hello: "world" },{ Auth: "Test" });// Post File via payload 文件路径为相对路径 相对地址, 示例: `/text/foo.txt`, 绝对路径为: `/data/app/data/text/foo.txt`。http.Post("http://127.0.0.1/path?foo=bar", "/path/root/file");// Post File via fileshttp.Post("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ f1: "/path/root/f1", f2: "/path/root/f2" });// Patchhttp.Patch("http://127.0.0.1/path?foo=bar");http.Patch("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Patch("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Patch("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });// Puthttp.Put("http://127.0.0.1/path?foo=bar");http.Put("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Put("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Put("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });// Deletehttp.Delete("http://127.0.0.1/path?foo=bar");http.Delete("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Delete("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Delete("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });// Headhttp.Head("http://127.0.0.1/path?foo=bar");http.Head("http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Head("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Head("http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });// Sendhttp.Send("POST", "http://127.0.0.1/path?foo=bar");http.Send("POST", "http://127.0.0.1/path?foo=bar", { name: "Lucy" });http.Send("POST","http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" });http.Send("POST","http://127.0.0.1/path?foo=bar",{ name: "Lucy" },{ hello: "world" },{ Auth: "Test" });}