මොකද්ද මේ XML Post ??

මොකද්ද මේක කියල දැන ගන්න (තියරි - පොතේ දැනුම ) ගන්න ආවනම් ඔබට හරියන ලිපිය මේක නෙවෙයි. (ගූග්ල් එකෙන් එව්ව හොයා ගන්න පුලුවන් ලේසියෙන්ම )
මම කියන්න යන්න සරල XML Post එකක් යවා ගන්න විදිහක්.
ඉස්සෙල්ලම වෙබ් පිටුවක් හදාගමු XML post එකක් අරගෙන සරලව txt file එකකට ගහන විදිහට.

private void Page_Load(object sender, EventArgs e)
        {
            Page.Response.ContentType = "text/xml";
            // Read XML data posted through HTTP
            StreamReader reader = new StreamReader(Page.Request.InputStream);
            String xmlData = reader.ReadToEnd();
            StreamWriter test = new StreamWriter(Server.MapPath("temp.txt"), true);
            test.Write(DateTime.Now  +" " + xmlData.ToString ());
            test.Close();
        }
හරි දැන් ඕකට xml එකක් යවන්න තියෙන්නෙ මොකක් හරි වෙන වැඩසටහනකින්.
සරලව යවන මෙතඩ් එකක් පල්ලෙහා තියෙන විදිහට අපිට හදා ගත්තැහැකි.

 public void DoXMLPost(string xmlData)
        {
            WebRequest req = null;
            WebResponse rsp = null;
            try
            {
                string uri = ConfigurationSettings.AppSettings["HTTPPostURL"].ToString(); ;
                req = WebRequest.Create(uri);
                //req.Proxy = WebProxy.GetDefaultProxy ();  // Enable if using proxy
                req.Method = "POST";        // Post method
                req.ContentType = "text/xml";     // content type
                // Wrap the request stream with a text-based writer
                StreamWriter writer = new StreamWriter(req.GetRequestStream());
                // Write the XML text into the stream
                writer.WriteLine(xmlData);
                writer.Close();
                // Send the data to the webserver
                rsp = req.GetResponse();

            }
            catch (WebException webEx)
            {
                throw webEx;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (req != null) req.GetRequestStream().Close();
                if (rsp != null) rsp.GetResponseStream().Close();
            }
        }
මෙව්ව ඉතින් එහෙන් මෙහෙන් හොයාගෙන මම එදිනෙදා පාවිච්චියට හරියන විදිහට මගෙ සිතුම් පැතුම් වල ඔබින විදිහට වෙනස් කරල තියෙන්නෙ. මතක නැහැ කොහෙන් ගත්තද කියල.
මොකක් හරි අවුලක් හරි මම කරල තියෙන විදිහෙ වැරැද්දක් හරි තියෙනව නම් කියන්න.


2 ප්‍රතිචාර:

änthräX said...

හොද වැඬක්. සුබපැතුම්. දිගටම ලියන්න...

Gayan said...

ස්තුතියි änthräX. ෂේප් එකේ වැඩිය වැඩක් නැති වෙලාවට ලියන්න තම්යි ලැහැස්තිය.

Post a Comment