Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

getting Cookies and Headers with HttpClient: it's obscure on documentation.

Moderators: larsivi kris

Posted: 05/30/09 15:04:58

Hi everyone, I'm trying to do two simples things:


show on console all the httpHeader of some webpage that was received with HttpGet?: i.e: Cout(page.getResponseHeaders()) (What i want is to iterate over all httpHeader)


show on console all cookie received by HttpGet?: i.e: Cout(page.getResponseHeaders().get(HttpHeader?.SetCookie?)) (What i want is get the cookie received on server and store on local variable, and later send back this cookie to the server.

someone can help-me with this ? Thanks :) --

I don't findout how to do it on documentation. I suggest that Tango docs be like PHP documentation, which users can write examples and alternatives ways to do the same thing.

--- AmBAr Amarelo

Author Message

Posted: 05/31/09 01:54:37

Hi folks, I'm back to post the solution for one of my initial problems on getResponseHeaders using the HttpGet? method:

Well, the problem occurred when i tried:

auto page = new HttpGet("");
char[] content = cast(char[]);
foreach(header; page.getResponseHeaders())

The result of this piece of code was always a lot of random garbage like:

"17259,20240,20572,20665",kHL:"pt-BR"};"webhp";{load:{t:{start:(new Date).getTime()}}};try{window.go

well, I supose that it's occur because i'm trying to get the headers after get the page content. So, i just try to get the headers before:

auto page = new HttpGet("");
foreach(header; page.getResponseHeaders())
char[] content = cast(char[]);

And now the result is aways null!

Well it is a combination of two issues:

1- The correct order for to call the methods there's not on documentation.
2- There's a bug on HttpGet method that reset all Headers.

well, I have get out around this (countered?? - Sory for my bad english) by combine HttpClient? with HttpGet? on this way:

	auto page = new HttpGet("");;
	foreach(header; page.getResponseHeaders())
	char[] content = cast(char[]);	

Just, call HttpClient?.Open() method before HttpGet?.read() and getResponseHeaders() after .open() method and Before .read()

Now, i get some thing like this:

 private, max-age=0
 Sun, 31 May 2009 01:45:20 GMT
 text/html; charset=ISO-8859-1
 PREF=ID=3657d191be12c72d:TM=1243734320:LM=1243734320:S=tDldGpHp1BfwDz9n; expires=Tue, 31-May-2011 01:45:20 GMT; path=/;

Well, I hope that I can came back here to solution my second problem that is: store server cookie on a variable and after send back to server this cookie.

Thank you :)


AmBAr Amarelo