먹는게 남는거다!

'EUC-kr'에 해당되는 글 2건

  1. ASP.NET Request QueryString encoding
  2. ASP.NET Request Form encoding

ASP.NET Request QueryString encoding

C#, ASP.NET
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
private System.Collections.Generic.Dictionary<stringstring> requestDic;
 
protected void Page_Load(object sender, EventArgs e)
{
    ParseRequestQueryStringData(System.Text.Encoding.GetEncoding(949));
 
    string t = GetRequestQueryString("strErrMsg");
    lbMessage.Text = t;
}
 
private void ParseRequestQueryStringData(System.Text.Encoding encoding)
{
    string url = HttpUtility.UrlDecode(Request.RawUrl, encoding);
    int s = url.IndexOf('?'0);
    if (s < 0)
    {
        return;
    }
 
    requestDic = new System.Collections.Generic.Dictionary<stringstring>();
    string requestData = "&" + url.Substring(s + 1+ "&";
 
    int pos = requestData.IndexOf('&'0);
    int pos2 = 0;
 
    string paramName;
    string paramValue;
 
    while (pos >= 0 && pos2 >= 0)
    {
        pos2 = requestData.IndexOf('=', pos);
 
        if (pos2 > 0)
        {
            paramName = requestData.Substring(pos + 1, pos2 - pos - 1);
 
            pos = requestData.IndexOf('&', pos2);
 
            if (pos > 0)
            {
                paramValue = requestData.Substring(pos2 + 1, pos - pos2 - 1);
                requestDic.Add(paramName, paramValue);
            }
        }
    }
}
 
private string GetRequestQueryString(string paramName)
{
    try
    {
        return requestDic[paramName];
    }
    catch (System.Collections.Generic.KeyNotFoundException keyEx)
    {
        return null;
    }
}
cs

 

ASP.NET Request Form encoding

C#, ASP.NET
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private static Dictionary<stringstring> GetEncodedForm(System.IO.Stream stream, System.Text.Encoding encoding)
{
    System.IO.StreamReader reader = new System.IO.StreamReader(stream, System.Text.Encoding.ASCII);
    return GetEncodedForm(reader.ReadToEnd(), encoding);
}
 
private static Dictionary<stringstring> GetEncodedForm(string urlEncoded, System.Text.Encoding encoding)
{
    Dictionary<stringstring> form = new Dictionary<stringstring>();
    string[] pairs = urlEncoded.Split("&".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
 
    foreach (string pair in pairs)
    {
        string[] pairItems = pair.Split("=".ToCharArray(), 2, StringSplitOptions.RemoveEmptyEntries);
        string name = HttpUtility.UrlDecode(pairItems[0], encoding);
        string value = (pairItems.Length > 1) ? HttpUtility.UrlDecode(pairItems[1], encoding) : null;
        form.Add(name, value);
    }
    return form;
}
cs

 

출처: https://stackoverflow.com/questions/1012120/iso-8859-1-to-utf8-in-asp-net-2