Hi again...
I have an Xml file that I need to send or upload from my Windows Application, to a server we have on the other side using asp.net application running on the server!
I know that its possible to use HttpWebRequest to post the data of my file to another ASP.Net App. working on the server side, so I made this code:
string result = "";
// postData is an Xml Data from the file 1.xml
string postData = GetDataFromXmlFile(“1.xml”);
string url =
HttpWebRequest objRequest2 = null;
HttpWebResponse objResponse2 = null;
try
{
objRequest2 = (HttpWebRequest) System.Net.HttpWebRequest.Create(url);
objRequest2.KeepAlive = false;
objRequest2.Method = "POST";
objRequest2.AllowAutoRedirect = true;
objRequest2.ContentLength = postData.Length;
objRequest2.ContentType = "text/xml";
objRequest2.Timeout = 100000;
objRequest2.CookieContainer = new CookieContainer();
objRequest2.AllowWriteStreamBuffering = true;
StreamWriter myWriter = new StreamWriter(objRequest2.GetRequestStream());
myWriter.Write(postData);
myWriter.Close();
objResponse2 = (HttpWebResponse)objRequest2.GetResponse();
using (StreamReader sr = new StreamReader(objResponse2.GetResponseStream(), Encoding.GetEncoding("windows-1252")) )
{
result = sr.ReadToEnd();
sr.Close();
}
}
catch(Exception ex)
{
Debug.WriteLine("get and exception"+ ex.ToString());
}
But what should I do or write to make my server side asp.net app. listen and accept my sent data and save them locally?
I tried the following code on the page load of my asp.net app but don’t work, since the postData is not displayed on the my asp.net page!!
private void Page_Load(object sender, System.EventArgs e)
{
StreamReader reader = new StreamReader(Page.Request.InputStream);
string xmlData = reader.ReadToEnd();
lblOutput.Text += xmlData;
}
Any idea how to do that easily?
Thanks