views:

39

answers:

1

I am trying to access a website through C# using the WebRequest and the WebResponse object,

I logged on to the site and preserved the cookie to further browse it, The problem is that the website is arabic and somehow I got a formatted message from the website indicating that my browser does not support arabic.

Perhaps I can add something to the request object to ensure the website that arabic is supported.

Thanks in advance.

This is the code I used, please let me know how to update it:

        string formUrl = "http://www.kuwaitlook.com/Ar/Residential.asp";
        string formParams = string.Format("Mega={0}", searchTarget);

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(formUrl);
        req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1);Accept-Language:ar";

        req.ContentType = "application/x-www-form-urlencoded";
        req.Method = "POST";
        req.Headers.Add("Cookie", cookieHeader);

        byte[] bytes = Encoding.ASCII.GetBytes(formParams);
        req.ContentLength = bytes.Length;

        using (Stream os = req.GetRequestStream()) {
            os.Write(bytes, 0, bytes.Length);
        }
        WebResponse resp = req.GetResponse();

        StreamReader streamReader = new StreamReader(resp.GetResponseStream());

        using (StreamWriter writer = new StreamWriter("text.xml")) {
            string line;
            while ((line = streamReader.ReadLine()) != null) {
                writer.WriteLine(line);
            }
        }
+1  A: 

Like Mikael suggested try this one:

HttpWebRequest request=(HttpWebRequest)WebRequest.Create("http://www.yourdomain.com");
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1);Accept-Language:ar"
Boris Modylevsky
I added the code I used, please let me know how can I update it
Ahmad Hajou
You can control languages that you support by the following string: "Accept-Language:ar", where ar for Arabic. For full list of languages see:http://www.loc.gov/standards/iso639-2/php/code_list.php
Boris Modylevsky