티스토리 뷰

🌈 .NET MVC

WebRequest & WebResponse

James Wetzel 2019. 4. 1. 11:13
728x90
반응형

                #region 트래킹 요청 XML 생성
                XmlNode trackingRequest = requestXmlDocument.CreateElement("TrackingRequest");
                requestXmlDocument.AppendChild(trackingRequest);

                XmlNode requestHeader = requestXmlDocument.CreateElement("RequestHeader");
                requestXmlDocument.AppendChild(requestHeader);

                XmlNode siteId = requestXmlDocument.CreateElement("SiteId");
                siteId.InnerText = "QXPRJP";
                requestHeader.AppendChild(siteId);

                XmlNode licenseKey = requestXmlDocument.CreateElement("LicenseKey");
                siteId.InnerText = "sdfsdfdsf";
                requestHeader.AppendChild(licenseKey);

                XmlNode requestNo = requestXmlDocument.CreateElement("RequestNo");
                siteId.InnerText = "8645";
                requestHeader.AppendChild(requestNo);

                XmlNode deliverNo = requestXmlDocument.CreateElement("DeliverNo");
                deliverNo.InnerText = "55";
                requestXmlDocument.AppendChild(deliverNo);

                XmlNode langCd = requestXmlDocument.CreateElement("LangCd");
                deliverNo.InnerText = "KO";
                requestXmlDocument.AppendChild(langCd);
                #endregion

                byte[] xmlRequestData = System.Text.Encoding.UTF8.GetBytes(requestXmlDocument.OuterXml);

                #region 트래킹 요청
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https:naver.com");
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentType = "application/xml";
                httpWebRequest.ContentLength = xmlRequestData.Length;

                using (Stream requestStream = httpWebRequest.GetRequestStream())
                {
                    requestStream.Write(xmlRequestData, 0, xmlRequestData.Length);
                }
                #endregion

                string xmlResponseData = string.Empty;

                #region 트래킹 요청에 대한 응답
                using (WebResponse httpWebResponse = httpWebRequest.GetResponse())
                {
                    Stream responseStream = httpWebResponse.GetResponseStream();
                    using (StreamReader streamReader = new StreamReader(responseStream))
                    {
                        xmlResponseData = streamReader.ReadToEnd();
                    }
                }
                #endregion

                reponseXmlDocument.LoadXml(xmlResponseData);

                #region 결과

                #endregion

728x90
반응형