I am trying to do something similar to this, but I do not fathom how to actually read the XML response. Where would the syntax recommended by @NikolaiDante actually go? Does anyone have a full working example? I would leave a comment there but rep not high enough...
Here is a link to the original post: Read XML Response From Page
I always use Hanselman example as I understand it, and it is easy to follow
public static string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.Proxy = new System.Net.WebProxy(ProxyString, true);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream ();
os.Write (bytes, 0, bytes.Length); //Push it out there
os.Close ();
System.Net.WebResponse resp = req.GetResponse();
if (resp== null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
And here is a link to the site so you can see and credit is given: enter link description here
Just take that string you are returning and do this...
string result = HttpPost(url, parameters);
XmlDocument xml = new XmlDocument();
xml.LoadXml(result);
or in your HttpPost method..
var stream = resp.GetResponseStream();
XmlDocument xml = new XmlDocument();
xml.Load(stream);
You can reference this link to parse the actual XML document
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.