postContent

Call post and return response content.

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

Examples

import std.json;
import std.string;
import std.stdio;
import std.range;

globalLogLevel(LogLevel.info);

/// ftp upload from range
info("Test getContent(ftp)");
auto r = getContent("ftp://speedtest.tele2.net/1KB.zip");
assert(r.length == 1024);

info("Test postContent ftp");
r = postContent("ftp://speedtest.tele2.net/upload/TEST.TXT", "test, ignore please\n".representation);
assert(r.length == 0);

info("Test receiveAsRange with GET(ftp)");
ubyte[] streamedContent;
auto rq = Request();
rq.useStreaming = true;
streamedContent.length = 0;
auto rs = rq.get("ftp://speedtest.tele2.net/1KB.zip");
auto stream = rs.receiveAsRange;
while( !stream.empty() ) {
    streamedContent ~= stream.front;
    stream.popFront();
}
assert(streamedContent.length == 1024);
//
info("ftp post ", "ftp://speedtest.tele2.net/upload/TEST.TXT");
rs = rq.post("ftp://speedtest.tele2.net/upload/TEST.TXT", "test, ignore please\n".representation);
assert(rs.code == 226);
info("ftp get  ", "ftp://speedtest.tele2.net/nonexistent", ", in same session.");
rs = rq.get("ftp://speedtest.tele2.net/nonexistent");
assert(rs.code != 226);
rq.useStreaming = false;
info("ftp get  ", "ftp://speedtest.tele2.net/1KB.zip", ", in same session.");
rs = rq.get("ftp://speedtest.tele2.net/1KB.zip");
assert(rs.code == 226);
assert(rs.responseBody.length == 1024);
info("ftp post ", "ftp://speedtest.tele2.net/upload/TEST.TXT");
rs = rq.post("ftp://speedtest.tele2.net/upload/TEST.TXT", "another test, ignore please\n".representation);
assert(rs.code == 226);
info("ftp get  ", "ftp://ftp.iij.ad.jp/pub/FreeBSD/README.TXT");
rs = rq.get("ftp://ftp.iij.ad.jp/pub/FreeBSD/README.TXT");
assert(rs.code == 226);
rq.authenticator = new BasicAuthentication("anonymous", "request@");
rs = rq.get("ftp://ftp.iij.ad.jp/pub/FreeBSD/README.TXT");
assert(rs.code == 226);
info("testing ftp - done.");

Meta