burakokumus
burakokumus

Reputation: 15

Fetching different language's HTML data from multilingual website

There is a multilingual website. When I view the html source from browser, I see the data in my language. But when I create a webrequest and fetch HTML, I get the data in English.

I want to fetch the HTML in Turkish. How can I do this?


This is how I fetch:

        WebRequest request = WebRequest.Create(webUrl);
        request.Method = "POST";
        byte[] byteArray = Encoding.UTF8.GetBytes("");
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = byteArray.Length;

        Stream dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

        WebResponse response = request.GetResponse();
        dataStream = response.GetResponseStream();

        StreamReader reader = new StreamReader(dataStream);
        htmlcontent = reader.ReadToEnd();

        reader.Close();
        dataStream.Close();
        response.Close();

Thanks in advance.

Upvotes: 0

Views: 432

Answers (3)

Oleks
Oleks

Reputation: 32323

Try to add Accept-Language request header. In .NET you could use HttpRequestHeader.ContentLanguage like this:

request.Headers[HttpRequestHeader.AcceptLanguage] = 
                                         "tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4";

Upvotes: 1

daryal
daryal

Reputation: 14919

WebHeaderCollection headerCollection = request.Headers;    
headerCollection.Add("Accept-Language:tr");

Upvotes: 2

Dominic Zukiewicz
Dominic Zukiewicz

Reputation: 8444

In your WebRequest, add a header entry for:

 Accept-Language: tk

Which will tell ASP.NET your preferred language. You have to have implemented language switching functionality. MSDN has a page for ASP.NET Globalization and Localization here.

Upvotes: 0

Related Questions