What i am trying to do here is make post request to Rest webserivce with xml data.
this is what i have right now but i am not sure how to pass my xml data
XElement xml = new XElement("MatchedOptions",
from m in _matchedOptionsList
select new XElement("Listing",
new XElement("DomainID", _trafficCopInputs.DomainID),
new XElement("AdSource", _trafficCopInputs.AdSource),
new XElement("Campaign", _trafficCopInputs.Campaign),
new XElement("AdGroup", _trafficCopInputs.AdGroup),
new XElement("RedirectURL", m.RedirectPath),
new XElement("FunnelKeyword", m.FunnelKeyword)));
HttpWebRequest req = WebRequest.Create("http://something.com/")
as HttpWebRequest;
req.Method = "POST";
req.ContentType = "text/xml";
req.ContentLength = 0;
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.WriteLine(xml.ToString());
I use the WebClient class:
WebClient webClient = new WebClient();
using (webClient)
{
requestInterceptor.OnRequest(webClient);
var enc = new ASCIIEncoding();
return enc.GetString(webClient.UploadData(uri, enc.GetBytes(dataAsString)));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With