Arul Posted March 17, 2008 Posted March 17, 2008 Hi I am very new to C# and using VS 2005 I need to read some data from database and should post the data in XML format to a Gateway (ASP website). I dont know anything regarding how to Post a XML request to a web page. I have formated the data in XML, but dont know how to move into next step Please advice me what are the steps that I need to take to post a XML request Quote
Arul Posted March 20, 2008 Author Posted March 20, 2008 I hv done this.... THANKS FOR PEOPLE WHO JUST VIEWED AND NOT REPLIED IN THIS SLEEPING FORUM Here is the code: private void button2_Click(object sender, EventArgs e) { WebRequest myRequest = null; WebResponse myResponse = null; try { string Page; string outputst; string fileName = "C:\\Regsitering_Data.xml"; string uri = "https://securee.xxxxxxxxxabc.com/xmlautomation/Upload.aspx"; myRequest = WebRequest.Create(uri); // Post method myRequest.Method = "POST"; // content type myRequest.ContentType = "text/xml"; // Wrap the request stream with a text-based writer StreamWriter writer = new StreamWriter(myRequest.GetRequestStream()); // Write the xml text into the stream writer.WriteLine(this.GetTextFromXMLFile(fileName)); writer.Close(); // Send the data to the webserver myResponse = myRequest.GetResponse(); Stream str = myResponse.GetResponseStream(); StreamReader strReader = new StreamReader(str); outputst = ""; while ((Page = strReader.ReadLine()) != null) { outputst = outputst + Page; } } catch (Exception Ex) { MessageBox.Show(Ex.Message.ToString()); } } private string GetTextFromXMLFile(string file) { StreamReader reader = new StreamReader(file); string ret = reader.ReadToEnd(); reader.Close(); return ret; } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.