Here is my code, see the part that says ???WHAT TO DO HERE??? I am not sure where I write this XML to in order to be able to send it in my POST via the objRequest there…
string project_id = context.Request.QueryString['project']; string person_id = context.Request.QueryString['person']; string post_date = context.Request.QueryString['date']; string post_hours = context.Request.QueryString['hours']; string case_num = context.Request.QueryString['case']; HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create('http://company.updatelog.com/projects/' + project_id + '/time_entries.xml'); objRequest.Method = 'POST'; objRequest.ContentType = 'application/xml'; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (' '); using (XmlWriter writer = XmlWriter.Create(?????WHAT TO DO HERE????, settings)) { writer.WriteStartElement('time-entry'); writer.WriteElementString('person-id', person_id); writer.WriteElementString('date', post_date); writer.WriteElementString('hours', post_hours); writer.WriteElementString('description', 'Worked on Case #' + case_num); writer.WriteEndElement(); } StreamWriter myWriter = null; try { myWriter = new StreamWriter(objRequest.GetRequestStream()); myWriter.Write(post_xml); } catch (Exception e) { context.Response.Write(e.Message); } finally { myWriter.Close(); }
You can just use an XmlTextWriter which takes a string builder which basically just writes it to memory.
Code: