HTTP

使用 http 对象发送 HTTP 请求,参数表与返回值与 http.* 处理器一致

约定

  1. 示例中约定应用根目录为 /data/app, 实际编写时需替换为应用根目录。
  2. 使用 <> 标识自行替换的内容。 例如: icon-<图标名称>, 实际编写时应替换为: icon-foo, icon-bar ...

示例

System

/data/app/scripts/test.js

function HttpTest() {
// Get
http.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" }
);
// Post
http.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 files
http.Post(
"http://127.0.0.1/path?foo=bar",
{ name: "Lucy" },
{ f1: "/path/root/f1", f2: "/path/root/f2" }
);
// Patch
http.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" }
);
// Put
http.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" }
);
// Delete
http.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" }
);
// Head
http.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" }
);
// Send
http.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 请求,参数表与返回值与 http.* 处理器一致

约定

  1. 示例中约定应用根目录为 /data/app, 实际编写时需替换为应用根目录。
  2. 使用 <> 标识自行替换的内容。 例如: icon-<图标名称>, 实际编写时应替换为: icon-foo, icon-bar ...

示例

System

/data/app/scripts/test.js

function HttpTest() {
// Get
http.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" }
);
// Post
http.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 files
http.Post(
"http://127.0.0.1/path?foo=bar",
{ name: "Lucy" },
{ f1: "/path/root/f1", f2: "/path/root/f2" }
);
// Patch
http.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" }
);
// Put
http.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" }
);
// Delete
http.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" }
);
// Head
http.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" }
);
// Send
http.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" }
);
}