postContent

Call post and return response content.

postContent
(
A...
)
(
string url
,)

Examples

1 import std.json;
2 import std.string;
3 import std.stdio;
4 import std.range;
5 import std.process;
6 
7 globalLogLevel(LogLevel.info);
8 // while we have no internal ftp server we can run tests in non-reloable networking environment
9 immutable unreliable_network = environment.get("UNRELIABLENETWORK", "false") == "true";
10 
11 /// ftp upload from range
12 info("Test getContent(ftp)");
13 auto r = getContent("ftp://speedtest.tele2.net/1KB.zip");
14 assert(unreliable_network || r.length == 1024);
15 
16 info("Test postContent ftp");
17 r = postContent("ftp://speedtest.tele2.net/upload/TEST.TXT", "test, ignore please\n".representation);
18 assert(unreliable_network || r.length == 0);
19 
20 info("Test receiveAsRange with GET(ftp)");
21 ubyte[] streamedContent;
22 auto rq = Request();
23 rq.useStreaming = true;
24 streamedContent.length = 0;
25 auto rs = rq.get("ftp://speedtest.tele2.net/1KB.zip");
26 auto stream = rs.receiveAsRange;
27 while( !stream.empty() ) {
28     streamedContent ~= stream.front;
29     stream.popFront();
30 }
31 assert(unreliable_network || streamedContent.length == 1024);
32 //
33 info("ftp post ", "ftp://speedtest.tele2.net/upload/TEST.TXT");
34 rs = rq.post("ftp://speedtest.tele2.net/upload/TEST.TXT", "test, ignore please\n".representation);
35 assert(unreliable_network || rs.code == 226);
36 info("ftp get  ", "ftp://speedtest.tele2.net/nonexistent", ", in same session.");
37 rs = rq.get("ftp://speedtest.tele2.net/nonexistent");
38 assert(unreliable_network || rs.code != 226);
39 rq.useStreaming = false;
40 info("ftp get  ", "ftp://speedtest.tele2.net/1KB.zip", ", in same session.");
41 rs = rq.get("ftp://speedtest.tele2.net/1KB.zip");
42 assert(unreliable_network || rs.code == 226);
43 assert(unreliable_network || rs.responseBody.length == 1024);
44 info("ftp post ", "ftp://speedtest.tele2.net/upload/TEST.TXT");
45 rs = rq.post("ftp://speedtest.tele2.net/upload/TEST.TXT", "another test, ignore please\n".representation);
46 assert(unreliable_network || rs.code == 226);
47 info("ftp get  ", "ftp://ftp.iij.ad.jp/pub/FreeBSD/README.TXT");
48 try {
49     rs = rq.get("ftp://ftp.iij.ad.jp/pub/FreeBSD/README.TXT");
50 } catch (ConnectError e)
51 {
52 }
53 assert(unreliable_network || rs.code == 226);
54 rq.authenticator = new BasicAuthentication("anonymous", "request@");
55 try {
56     rs = rq.get("ftp://ftp.iij.ad.jp/pub/FreeBSD/README.TXT");
57 } catch (ConnectError e)
58 {
59 }
60 assert(unreliable_network || rs.code == 226);
61 info("testing ftp - done.");

Meta