-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.cfm
100 lines (88 loc) · 4.17 KB
/
test.cfm
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<cffunction name="flush">
<cfflush />
</cffunction>
<cfscript>
function dumpError(string content) {
writeOutput('<div style="border: 2px solid red; margin: 15px 0; padding:10px;">
#content#
</div>'
);
}
writeOutput("<br/><h1>GET</h1>");
target = 'http://httpbin.org/get';
cURL = new cURL(target);
res = cURL.exec();
expected = deserializeJSON('{"args": {}, "headers": { "Accept": "*/*", "Host": "httpbin.org", "User-Agent": "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3" }, "origin": "5.149.142.22", "url": "http://httpbin.org/get" }');
writeDump(res);
if(deserializeJSON(res.response.data).headers.Host != expected.headers.host) {
dumpError('Error: not equal to <br/> #serializeJson(expected)#');
}
flush();
writeOutput("<br/><h1>GET with qs</h1>");
target = 'http://httpbin.org/get';
cURL = new cURL(target).field('abc', 'def');
res = cURL.exec();
expected = deserializeJSON('{"args": { "abc": "def" }, "headers": { "Accept": "*/*", "Host": "httpbin.org", "User-Agent": "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3" }, "origin": "5.149.142.22", "url": "http://httpbin.org/get" }');
writeDump(res);
if(deserializeJSON(res.response.data).args.abc != expected.args.abc) {
dumpError('Error: not equal to <br/> #serializeJson(expected)#');
}
flush();
writeOutput("<br/><h1>POST</h1>");
target = 'http://httpbin.org/post';
cURL = new cURL(target)
.method('post')
.field('abc', 'def')
.field('azerty', 123)
;
res = cURL.exec();
expected = deserializeJSON('{"args": {}, "data": "", "files": {}, "form": { "abc": "def", "azerty": "123" }, "headers": { "Accept": "*/*", "Content-Length": "18", "Content-Type": "application/x-www-form-urlencoded", "Host": "httpbin.org", "User-Agent": "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3" }, "json": null, "origin": "5.149.142.22", "url": "http://httpbin.org/post" }');
writeDump(res);
if(!structKeyExists(expected.form, 'abc') || !structKeyExists(expected.form, 'azerty')) {
dumpError('Error: not equal to <br/> #expected#');
}
writeOutput("<br/><h1>POST xml body</h1>");
target = 'http://httpbin.org/post';
expected = '<xml><foo>bar</foo></xml>';
cURL = new cURL(target)
.method('post')
.header('Content-Type', 'text/xml')
.body(expected)
;
res = cURL.exec();
writeDump(res);
responseData = deserializeJSON(res.response.data);
if(responseData.data != expected) {
dumpError('Error: not equal to <br/> #expected#');
}
flush();
writeOutput("<br/><h1>POST (multipart)</h1>");
target = 'http://httpbin.org/post';
cURL = new cURL(target)
.method('post')
.multipart(true)
.field('abc', 'def')
.field('azerty', 123)
;
res = cURL.exec();
expected = deserializeJSON('{"args": {}, "data": "", "files": {}, "form": { "abc": "def", "azerty": "123" }, "headers": { "Accept": "*/*", "Content-Length": "239", "Content-Type": "multipart/form-data; boundary=----------------------------7cb7997bd60e", "Host": "httpbin.org", "User-Agent": "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3" }, "json": null, "origin": "5.149.142.22", "url": "http://httpbin.org/post" }');
writeDump(res);
if(!structKeyExists(expected.form, 'abc') || !structKeyExists(expected.form, 'azerty')) {
dumpError('Error: not equal to <br/> #expected#');
}
flush();
writeOutput("<br/><h1>POST (json)</h1>");
target = 'http://httpbin.org/post';
cURL = new cURL(target)
.method('post')
.json()
.field('abc', 'def')
.field('azerty', 123)
;
res = cURL.exec();
expected = deserializeJSON('{"args": {}, "data": "", "files": {}, "form": { "abc": "def", "azerty": "123" }, "headers": { "Accept": "*/*", "Content-Length": "239", "Content-Type": "multipart/form-data; boundary=----------------------------7cb7997bd60e", "Host": "httpbin.org", "User-Agent": "curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3" }, "json": null, "origin": "5.149.142.22", "url": "http://httpbin.org/post" }');
writeDump(res);
if(!structKeyExists(expected.form, 'abc') || !structKeyExists(expected.form, 'azerty')) {
dumpError('Error: not equal to <br/> #expected#');
}
</cfscript>