Code For Posting
To post XML, use the following function:
WebRequest req = null;
WebResponse rsp = null;
try
{
string fileName = "C:\test.xml";
string uri = "http://localhost/PostXml/Default.aspx";
req = WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "text/xml";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.WriteLine(this.GetTextFromXMLFile(fileName));
writer.Close();
rsp = req.GetResponse();
}
catch(WebException webEx)
{
}
catch(Exception ex)
{
}
finally
{
if(req != null) req.GetRequestStream().Close();
if(rsp != null) rsp.GetResponseStream().Close();
}Function to read xml data from local system
private string GetTextFromXMLFile(string file)
{
StreamReader reader = new StreamReader(file);
string ret = reader.ReadToEnd();
reader.Close();
return ret;
}
Code For Reading Posted Data
Now, on the Web server in the ASP.NET page, write the following code to access the posted data:
private void Page_Load(object sender, EventArgs e)
{
page.Response.ContentType = "text/xml";
StreamReader reader = new StreamReader(page.Request.InputStream);
String xmlData = reader.ReadToEnd();
}