This repository has been archived by the owner on Apr 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Main.hx
61 lines (44 loc) · 1.55 KB
/
Main.hx
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
package ;
import com.akifox.asynchttp.*;
class Main {
var wikipediaHaxeFingerprint:String = null;
static function main() {
// Force log to console (usually enabled only on -debug)
AsyncHttp.logEnabled = true;
#if sys
trace('\n>> Enter an URL and press [enter] (also HTTP://):\nexample: http://wikipedia.com/wiki/wikipedia');
while (true) {
var input = Sys.stdin().readLine();
if (input=="") break;
new HttpRequest({url:input,callback:onResponse}).send();
}
trace('>> Goodbye!');
#else
new HttpRequest({url:"http://wikipedia.com/wiki/wikipedia",callback:onResponse}).send();
#end
}
static function onResponse(response:HttpResponse):Void {
trace('-------------------------');
trace(response);
if (response.isOK) {
/* if (response.isText)
trace('TEXT\n'+response.toText());
if (response.isJson)
trace('JSON\n'+response.toJson());
if (response.isXml)
trace('XML\n'+response.toXml());*/
trace("First 500 chars:");
trace(response.toText().substr(0,500));
if (response.isBinary) {
//trace(response.content); // BYTES DATA
trace('[ Binary file <' + response.contentType + '> "' + response.filename + '" ' + Std.int(response.contentLength/1024*100)/100 + 'kb]');
} else {
//trace(response.content); // STRING DATA
trace('[ Text file <' + response.contentType + '> "' + response.filename + '" ' + Std.int(response.contentLength/1024*100)/100 + 'kb]');
}
} else {
trace('Response error (' + response.status + ') ['+response.error+']');
}
trace('-------------------------\n\n\n');
}
}