A
AhWau
I wrote a function to read content of web as below:
public static class Read
{
public static string WebContent(string PageLink, int EncodeType)
{
string Content = "";
int Counter = 0;
while (Content == "" && Counter <= 9999)
{
try
{
HttpWebRequest HWWebContent =
(HttpWebRequest)WebRequest.Create(PageLink);
HWWebContent.CachePolicy = new
System.Net.Cache.HttpRequestCachePolicy(System.Net.Cache.HttpRequestCacheLevel.NoCacheNoStore);
HWWebContent.Timeout = 3000;
HWWebContent.UserAgent = "Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
HttpWebResponse HWResponseWebContent =
(HttpWebResponse)HWWebContent.GetResponse();
StreamReader SRWebContent = new
StreamReader(HWResponseWebContent.GetResponseStream(), (EncodeType == 1) ?
Encoding.Default : Encoding.UTF8);
Content = SRWebContent.ReadToEnd();
SRWebContent.Close();
HWResponseWebContent.Close();
}
catch
{
Counter++;
Thread.Sleep(300);
}
}
return Content;
} // public static string WebContent(string PageLink)
}
now, i use this statement to selecting encoding method
(EncodeType == 1) ? Encoding.Default : Encoding.UTF8
but i want to select betwwen much more other encoding
and write a case or if statement at the begining of function like this
if(EncodeType ==1)
VAR = Encoding.Default;
else if(EncodeType ==2)
VAR = Encoding.UTF8;
else if(EncodeType ==3)
VAR = Encoding.ASCII;
else
..
..
..
is it possible?
Thank you so much
public static class Read
{
public static string WebContent(string PageLink, int EncodeType)
{
string Content = "";
int Counter = 0;
while (Content == "" && Counter <= 9999)
{
try
{
HttpWebRequest HWWebContent =
(HttpWebRequest)WebRequest.Create(PageLink);
HWWebContent.CachePolicy = new
System.Net.Cache.HttpRequestCachePolicy(System.Net.Cache.HttpRequestCacheLevel.NoCacheNoStore);
HWWebContent.Timeout = 3000;
HWWebContent.UserAgent = "Mozilla/4.0 (compatible;
MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
HttpWebResponse HWResponseWebContent =
(HttpWebResponse)HWWebContent.GetResponse();
StreamReader SRWebContent = new
StreamReader(HWResponseWebContent.GetResponseStream(), (EncodeType == 1) ?
Encoding.Default : Encoding.UTF8);
Content = SRWebContent.ReadToEnd();
SRWebContent.Close();
HWResponseWebContent.Close();
}
catch
{
Counter++;
Thread.Sleep(300);
}
}
return Content;
} // public static string WebContent(string PageLink)
}
now, i use this statement to selecting encoding method
(EncodeType == 1) ? Encoding.Default : Encoding.UTF8
but i want to select betwwen much more other encoding
and write a case or if statement at the begining of function like this
if(EncodeType ==1)
VAR = Encoding.Default;
else if(EncodeType ==2)
VAR = Encoding.UTF8;
else if(EncodeType ==3)
VAR = Encoding.ASCII;
else
..
..
..
is it possible?
Thank you so much