|
23 | 23 | toJSON: () => any; |
24 | 24 | toImage: () => image_module.Image; |
25 | 25 | } |
| 26 | +``` |
26 | 27 |
|
27 | | - // GET request |
28 | | - http.request({ |
29 | | - url: "http://ip.jsontest.com/", |
30 | | - method: "GET", |
31 | | - headers: { "Content-Type" : "application/json" } |
32 | | - }).then(function (r) { |
33 | | - var status = r.statusCode; |
34 | | - |
35 | | - for (var header in r.headers) { |
36 | | - // |
37 | | - } |
38 | | - |
39 | | - var result = r.content.toJSON(); |
40 | | - }).fail(function (e) { console.log(e) }); |
41 | | - |
42 | | - // POST request |
43 | | - http.request({ |
44 | | - url: "http://posttestserver.com/post.php?dump&html&dir=test", |
45 | | - method: "POST", |
46 | | - headers: { "Content-Type" : "application/x-www-form-urlencoded" }, |
47 | | - content: "MyVariableOne=ValueOne&MyVariableTwo=ValueTwo" |
48 | | - }).then(function (r) { |
49 | | - var status = r.statusCode; |
50 | | - |
51 | | - for (var header in r.headers) { |
52 | | - // |
53 | | - } |
54 | | - |
55 | | - var result = r.content.toString(); |
56 | | - }).fail(function (e) { console.log(e) }); |
57 | | - |
58 | | - // PUT request |
59 | | - var data = YOUR_IMAGE_DATA; |
60 | | - http.request({ |
61 | | - url: "http://httpbin.org/put", |
62 | | - method: "PUT", |
63 | | - headers: { |
64 | | - "Content-Type": "image/jpg", |
65 | | - "Content-Length": data.length() + "" |
66 | | - }, |
67 | | - content: data |
68 | | - }).then(function (r) { |
69 | | - console.log(r.content.toString()) |
70 | | - }).fail(function (e) { console.log(e) }); |
71 | | - |
72 | | - http.getString("http://www.reddit.com/").then(function(result) { |
73 | | - // Result is string! |
74 | | - }).fail(function(e) { console.log(e); }); |
75 | | - |
76 | | - http.getJSON("http://www.reddit.com/r/aww.json?limit=10").then(function(result) { |
77 | | - // Result is JSON! |
78 | | - }).fail(function(e) { console.log(e); }); |
79 | | - |
80 | | - http.getImage("http://www.google.com/images/errors/logo_sm_2.png").then(function(result) { |
81 | | - // Result is tk.ui.Image! |
82 | | - }).fail(function(e) { console.log(e); }); |
83 | | - |
84 | | -``` |
| 28 | +More info: https://github.com/telerik/xPlatCore/blob/master/Documentation/Snippets/http.md |
0 commit comments