XML receive and parse via http

-- C# 2013. 8. 8. 10:39
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

// Receive
XmlDocument g_doc = null;


HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://xxxxxxxx/yyy.php");
req.SendChunked = true;
req.KeepAlive = false;
req.Timeout = 3000;

req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";


try
{
    StreamWriter sw = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
    sw.Write("a=1&b=2");
    sw.Close();
}
catch (Exception e)
{
    return "서버접속을 실패했습니다. (" + e.Message + ")";
}


try
{
    HttpWebResponse res = (HttpWebResponse)req.GetResponse();
    Stream stream = res.GetResponseStream();
    StreamReader sr = new StreamReader(stream, System.Text.Encoding.Default);

    string strBody = sr.ReadToEnd();

    sr.Close();
    stream.Close();
    res.Close();

                
    g_doc = new XmlDocument();
    g_doc.LoadXml(strBody);
}
catch (Exception e)
{
    return "데이터수신 중 에러가 발생했습니다. (" + e.Message + ")";
}


XmlNodeList items = g_doc.SelectNodes("//root");
string strRetCode = items.Item(0).SelectSingleNode("ret_code").InnerText;
string strRetMsg = items.Item(0).SelectSingleNode("ret_msg").InnerText;

           
if (strRetCode.Equals("0000"))
{
    XmlNodeList items = g_doc.SelectNodes("//root/items");
    string strItemName = items.Item(0).SelectSingleNode("item_name").InnerText;
    string strItemCount = items.Item(0).SelectSingleNode("item_cnt").InnerText;
}

posted by 어린왕자악꿍