How can I make GET and POST HTTP requests? I found Socket solution, but is it all?
string host = "google.com";
ushort port = 80;
Socket listener = new TcpSocket;
assert(listener.isAlive);
listener.blocking = false;
listener.connect(new InternetAddress(host, port));
char[] msg;
char[] req = cast(char[]) "GET /search.php HTTP/1.1\r\nHost: google.com\r\n\r\n";
listener.send(req);
Take a look at std.net.curl
. It has get
and post
methods:
import std.net.curl;
auto content = get("d-lang.appspot.com/testUrl2");
// --
auto content = post("d-lang.appspot.com/testUrl2", [1,2,3,4]);