All I want is to send xml data from C# desktop application to ASP.Net webpage. My C# code look like this.
public string SendRequest()
{ string data = "<?xml version="1.0"?><author>Gambardella, Matthew</author>";
string _result;
Uri uri = new Uri("http://localhost:62511/Default");
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "text/xml";
var writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();
var response = (HttpWebResponse)request.GetResponse();
var streamResponse = response.GetResponseStream();
var streamRead = new StreamReader(streamResponse);
Console.Write(response.StatusCode);
_result = streamRead.ReadToEnd().Trim();
streamRead.Close();
streamResponse.Close();
response.Close();
return _result;
}
My ASP .Net Code looks like this
protected void Page_Load(object sender, EventArgs e)
{
using (var reader = new StreamReader(Request.InputStream))
{
string xml = reader.ReadToEnd();
labelsam.Text = xml;
}
....
}
labelsam is a label on web page.But I get nothin in labelsam.Is there anyway to check whether the data is received.Also whats wrong with code?
IDisposable. Make use ofusing.