Hi Martin,
I am trying without success. The response from the server in question keeps
telling me it is not receiving anything. Does this look correct?
System.Net.HttpWebRequest httpRequest =
(System.Net.HttpWebRequest)System.Net.WebRequest.C reate("https://esqa.moneris.com:443/gateway2/servlet/MpgRequest");
httpRequest.Method = "POST";
httpRequest.ContentType ="text/xml";
System.Xml.XmlTextWriter xmlWriter = new
System.Xml.XmlTextWriter(httpRequest.GetRequestStr eam(),
System.Text.Encoding.UTF8);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("request");
xmlWriter.WriteElementString("store_id", store_id);
xmlWriter.WriteElementString("api_token", api_token);
xmlWriter.WriteStartElement("purchase");
xmlWriter.WriteElementString("order_id",
System.Guid.NewGuid().ToString());
xmlWriter.WriteElementString("amount", amount);
xmlWriter.WriteElementString("pan",
CCNumberBox.Text.Trim());
xmlWriter.WriteElementString("expdate",
MonthList.SelectedValue + YearList.SelectedValue);
xmlWriter.WriteElementString("crypt_type", crypt);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Close();
Maybe i am sending in the wrong Encoding? I've tried writing the xml to file
and it works and looks correct. I'm just not sure that it's writing to the
post stream?Thanks again for your help.
Rich
"Martin Honnen" wrote:
Rich Williams wrote:
"If you want to create the XML while making the HTTP POST request you could
use the OpenWrite method of WebClient and them create an XmlTextWriter on the
stream and write out the XML as needed."
It seems to make sense but I'm just not sure if I can then retrieve a
response?
It is probably better to then look at WebRequest/HttpWebRequest to POST
the XML data and receive the response e.g.
HttpWebRequest httpRequest = (HttpWebRequest)
WebRequest.Create("http://example.com/2005/04/receiveXML.aspx");
httpRequest.Method = "POST";
// now use XmlWriter on httpRequest.GetRequestStream
// to write out the XML
// then use
HttpWebResponse httpResponse = (HttpWebResponse)
httpRequest.GetResponse();
// now use properties/method of the response to read out
// headers or the response stream
// for instance
XmlDocument responseXML = new XmlDocument();
responseXML.load(httpResponse.GetResponseStream()) ;
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/