request_sender.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. // The entry file of your WebAssembly module.
  6. import * as console from "../wamr_app_lib/console"
  7. import * as timer from "../wamr_app_lib/timer"
  8. import * as request from "../wamr_app_lib/request"
  9. export function on_init() : void {
  10. var payload = String.UTF8.encode("test message");
  11. request.post("/test", payload, payload.byteLength, "", (resp) => {
  12. if (resp != null) {
  13. console.log("Post Success");
  14. if (resp.payload != null) {
  15. console.log(" response payload:")
  16. console.log(" " + String.UTF8.decode(resp.payload!) + "\n");
  17. }
  18. }
  19. else
  20. console.log("Post Timeout");
  21. });
  22. }
  23. export function on_destroy() : void {
  24. }
  25. /* Function below are requred by wamr runtime, don't remove or modify them */
  26. export function _on_timer_callback(on_timer_id: i32): void {
  27. timer.on_timer_callback(on_timer_id);
  28. }
  29. export function _on_request(buffer_offset: i32, size: i32): void {
  30. request.on_request(buffer_offset, size);
  31. }
  32. export function _on_response(buffer_offset : i32, size: i32): void {
  33. request.on_response(buffer_offset, size);
  34. }