import std.file; import std.path; globalLogLevel(LogLevel.info); info("Check POST files"); /// preapare files auto tmpd = tempDir(); auto tmpfname1 = tmpd ~ dirSeparator ~ "request_test1.txt"; auto f = File(tmpfname1, "wb"); f.rawWrite("file1 content\n"); f.close(); auto tmpfname2 = tmpd ~ dirSeparator ~ "request_test2.txt"; f = File(tmpfname2, "wb"); f.rawWrite("file2 content\n"); f.close(); /// /// files ready, send them. /// File f1 = File(tmpfname1, "rb"); File f2 = File(tmpfname2, "rb"); scope(exit) { f1.close(); f2.close(); } MultipartForm form = MultipartForm(). add(formData("Field1", cast(ubyte[])"form field from memory")). add(formData("Field2", cast(ubyte[])"file field from memory", ["filename":"data2"])). add(formData("File1", f1, ["filename":"file1", "Content-Type": "application/octet-stream"])). add(formData("File2", f2, ["filename":"file2", "Content-Type": "application/octet-stream"])); auto rq = HTTPRequest(); auto rs = rq.post("http://httpbin.org/post", form);
This struct used to bulld POST's to forms.