Reading web pages

Bystroushaak bystrousak at kitakitsune.org
Fri Jan 20 07:08:39 PST 2012


There are two ways:

Change global variable for module:

dhttpclient.DefaultHeaders = dhttpclient.IEHeaders; // or your own

This will change headers for all clients.

---

Change instance headers:

string[string] my_headers = dhttpclient.FFHeaders; // there are more 
headers than just User-Agent and you have to copy it
my_headers["User-Agent"] = "My own spider!";

HTTPClient navegador = new HTTPClient();
navegador.setClientHeaders(my_headers);

---

Headers are defined as:

public enum string[string] FFHeaders = [
   "User-Agent" : "Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; 
rv:1.9.2.3) Gecko/20100401 Firefox/3.6.13",
   "Accept" : 
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain",
   "Accept-Language" : "cs,en-us;q=0.7,en;q=0.3",
   "Accept-Charset" : "utf-8",
   "Keep-Alive" : "300",
   "Connection" : "keep-alive"
];

/// Headers from firefox 3.6.13 on Linux
public enum string[string] LFFHeaders = [
   "User-Agent" : "Mozilla/5.0 (X11; U; Linux i686; cs; rv:1.9.2.3) 
Gecko/20100401 Firefox/3.6.13",
   "Accept" : 
"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain",
   "Accept-Language" : "cs,en-us;q=0.7,en;q=0.3",
   "Accept-Charset" : "utf-8",
   "Keep-Alive" : "300",
   "Connection" : "keep-alive"
];

Accept, Accept-Charset, Kepp-ALive and Connection are important and if 
you redefine it, module can stop work with some servers.

On 20.1.2012 15:56, Xan xan wrote:
> On the other hand, I see dhttpclient  identifies as
>   "Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.9.2.3)
> Gecko/20100401 Firefox/3.6.13"
>
> How can I change that?


More information about the Digitalmars-d-learn mailing list