Reading web pages

Kapps Kapps at NotValidEmail.com
Thu Jan 19 16:33:22 PST 2012


The host is www.google.com - http is only a web protocol. The DNS lookup 
is independent of HTTP, and thus should not include it. Note that you're 
also missing a space after the GET. Also, in terms of the example given, 
some servers won't like you not using the Host header, some won't like 
the GET being an absolute path instead of relative (but the two combined 
should make most accept it). There's a CURL wrapper added, and a higher 
level version should be available within the next release or two, you 
make want to look into that.

On 19/01/2012 9:30 AM, Xan xan wrote:
> Hi,
>
> I want to simply code a script to get the url as string in D 2.0.
> I have this code:
>
> //D 2.0
> //gdmd-4.6
> import std.stdio, std.string, std.conv, std.stream;
> import std.socket, std.socketstream;
>
> int main(string [] args)
> {
>      if (args.length<  2) {
> 		writeln("Usage:");
> 		writeln("   ./aranya {<url1>,<url2>, ...}");
> 		return 0;
> 	}
> 	else {
> 		foreach (a; args[1..$]) {
> 			Socket sock = new TcpSocket(new InternetAddress(a, 80));
> 			scope(exit) sock.close();
> 			Stream ss = new SocketStream(sock);
> 			ss.writeString("GET" ~ a ~ " HTTP/1.1\r\n");
> 			writeln(ss);
> 		}
> 		return 0;
> 	}
> }
>
>
> but when I use it, I receive:
> $ ./aranya http://www.google.com
> std.socket.AddressException at ../../../src/libphobos/std/socket.d(697):
> Unable to resolve host 'http://www.google.com'
>
> What fails?
>
> Thanks in advance,
> Xan.



More information about the Digitalmars-d-learn mailing list