I am currently working on some functionality that makes an httppost then get a response.
Here's the code I'm currently working with:
public string SubmitRequest(string postUrl, string contentType, string postValues)
{
var req = WebRequest.Create(postUrl);
req.Method = "POST";
req.ContentType = contentType;
try
{
using (var reqStream = req.GetRequestStream())
{
var writer = new StreamWriter(reqStream);
writer.WriteLine(postValues);
}
var resp = req.GetResponse();
using (var respStream = resp.GetResponseStream())
{
var reader = new StreamReader(respStream);
return reader.ReadToEnd().Trim();
}
}
catch(WebException ex)
{
// do something here
}
return string.Empty;
}
The function returns xml in string format, for instance:
<result>
<code>Failed</code>
<message>Duplicate Application</message>
</result>
This needs to be converted into a class object - but i'm not sure how to go about it in the correct way.
Any advice appreciated.