Source file http_request.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
open Js_of_ocaml
type js_string = Js.js_string Js.t
class type xmlHttpRequest =
object
method open_: js_string -> js_string -> unit Js.meth
method setRequestHeader: js_string -> js_string -> unit Js.meth
method send_string: js_string -> unit Js.meth
method readyState: int Js.readonly_prop
method status: int Js.readonly_prop
method statusText: js_string Js.readonly_prop
method responseText: js_string Js.readonly_prop
end
type t = xmlHttpRequest Js.t
let event_target (req: t): Event_target.t =
Obj.magic req
let make
(_method: string)
(url: string)
(: (string * string) list)
(body: string)
: t
=
let req: xmlHttpRequest Js.t =
let request = Js.Unsafe.global##._XMLHttpRequest
in
new%js request
in
req##open_ (Js.string _method) (Js.string url);
List.iter
(fun (name, value) ->
req##setRequestHeader (Js.string name) (Js.string value)
)
headers;
req##send_string (Js.string body);
req
let ready_state (req: t): int =
req##.readyState
let status (req: t): int =
req##.status
let response_text_value (req: t): Base.Value.t =
Obj.magic req##.responseText
let response_text_string (req: t): string =
Js.to_string req##.responseText