Кодировка в WebClient - C#
Формулировка задачи:
Всем доброго времени суток.
Использую следующий код
При получение страницы вместо русских знаков получаю знаки вопроса.(Куки изменены.)
public static string htmlPage(string urlx)
{
while (true)
{
if (data.userAgent >= 100)
{
return "err";
break;
}
{
string s;
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
client.Headers.Add("user-agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20130406 Firefox/20");
client.Headers.Add(HttpRequestHeader.Cookie,
"remixmdv=EwYvwTYd1у30xhmMk;"+
"remixsid=b45ee3cc39717у4035e1cd4700a2d3fe60c7f370b72062249cec8;" +
"remixstid=1681e47838_a8уfad933d3d8ca226;"+
"p=c088bb92ae774568eуaa339e6f8ceca54c54a0a77732d4c0f4e16;" +
"t=f7fe7528eda0уb7cfe49wb642");
using (Stream data = client.OpenRead(urlx))
{
using (StreamReader reader = new StreamReader(data))
{
return reader.ReadToEnd();
}
}
break;
}
catch
{
++data.userAgent;
}
}
}//Загрузка html страници
try не дописал
Решение задачи: «Кодировка в WebClient»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Vk.htmlPage(@"http://vk.com/e.patronum"));
Console.ReadKey();
}
}
class Vk
{
public static string htmlPage(string urlx)
{
while (true)
{
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
using (Stream data = client.OpenRead(urlx))
{
using (StreamReader reader = new StreamReader(data, Encoding.UTF8))
{
string tt = reader.ReadToEnd();
StreamWriter sw = new StreamWriter("htm.txt");
sw.Write(tt);
sw.Close();
return tt;
}
}
}
}//Загрузка html
}
}