vibe.d beta banner
get vibe.d
0.7.30

writeFormBody - multiple declarations

  • Function writeFormBody
  • Function writeFormBody

Function writeFormBody

Writes a vibe.http.client.HTTPClientRequest body as URL encoded form data.

Prototype

void writeFormBody(
  HTTPClientRequest req,
  const(string[string]) form
);

Example

import vibe.core.log;
import vibe.http.client;
import vibe.http.form;
import vibe.stream.operations;

void sendForm()
{
	requestHTTP("http://example.com/form",
		(scope req) {
			req.method = HTTPMethod.POST;
			req.writeFormBody(["field1": "value1", "field2": "value2"]);
		},
		(scope res) {
			logInfo("Response: %s", res.bodyReader.readAllUTF8());
		});
}

Function writeFormBody

Writes a vibe.http.client.HTTPClientRequest body as URL encoded form data.

Prototype

void writeFormBody(PairRange)(
  HTTPClientRequest req,
  PairRange form
)
if (isTuple!(ElementType!PairRange) && ElementType!PairRange.length == 2);

Parameters

NameDescription
form range of t = Tuple!(string, string), where t[0] is the name and t[1] the value of a form entry.

Example

import vibe.core.log;
import vibe.http.client;
import vibe.http.form;
import vibe.stream.operations;
import std.range;

void sendForm()
{
	string[] names = ["foo", "bar", "baz"];
	string[] values = ["1", "2", "3"];
	auto form = zip(names, values);
	requestHTTP("http://example.com/form",
		(scope req) {
			req.method = HTTPMethod.POST;
			req.writeFormBody(form);
		},
		(scope res) {
			logInfo("Response: %s", res.bodyReader.readAllUTF8());
		});
}
Authors

Sönke Ludwig, Jan Krüger

Copyright

© 2012-2015 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.