Reading web pages

Xan xan xancorreu at gmail.com
Fri Jan 20 06:24:13 PST 2012


Thanks for that. The standard library would include it. It will easy
the things.... high level, please.

For the other hand, how to specify the protocol? It's not the same
http://foo than ftp://foo

Thanks,
Xan.

2012/1/20 Bystroushaak <bystrousak at kitakitsune.org>:
> You can always use my module:
>  https://github.com/Bystroushaak/DHTTPClient
>
>
> On 19.1.2012 20:24, Timon Gehr wrote:
>>
>> On 01/19/2012 04:30 PM, 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.
>>
>>
>> The protocol specification is part of the get request.
>>
>> ./aranaya www.google.com
>>
>> seems to actually connect to google. (it still does not work fully, I
>> get back 400 Bad Request, but maybe you can figure it out)


More information about the Digitalmars-d-learn mailing list