Needing help with basic HTTP requests..
Adam D. Ruppe
destructionator at gmail.com
Tue Jul 9 05:19:24 PDT 2013
On Tuesday, 9 July 2013 at 09:03:32 UTC, AlexMcP wrote:
> writeln("Connection Error ", Socket.ERROR);
First tip: Socket.ERROR is a constant, so printing it doesn't
help much (as you probably noticed). More helpful is the function
lastSocketError(), which returns a string with some details.
writeln("Connection Error ",
Socket.ERROR, " ", lastSocketError());
Which tells you:
Connection Error -1 Resource temporarily unavailable
The reason that is an error is because you turned off blocking.
listener.blocking = false;
So, since the connection hasn't had a chance to get established
and transfer data yet, instead of waiting for it to finish when
you called receive, it returned the error telling you to try
again later.
The simplest thing to do here is to comment out that blocking =
false line, letting receive just wait until data is available.
Another option is to use Socket.select to notify you when data is
available, and only receive then.
After that, make sure the req literal is all on one line to avoid
http 400 errors (not sure if that was a result of copy/paste or
not, probably) and you should get a response.
Another note: casting a string literal to char[] is usually a bad
idea, because you can't write to them anyway. Best to just leave
them typed as string. It should all still work the same after
doing that.
Finally, if you want a higher level library to do this, check out
std.net.curl: http://dlang.org/phobos/std_net_curl.html
More information about the Digitalmars-d-learn
mailing list