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.Http WebRequest httpRequest =
(System.Net.Htt pWebRequest)Sys tem.Net.WebRequ est.Create("htt ps://esqa.moneris.co m:443/gateway2/servlet/MpgRequest");
httpRequest.Met hod = "POST";
httpRequest.Con tentType ="text/xml";
System.Xml.XmlT extWriter xmlWriter = new
System.Xml.XmlT extWriter(httpR equest.GetReque stStream(),
System.Text.Enc oding.UTF8);
xmlWriter.Write StartDocument() ;
xmlWriter.Write StartElement("r equest");
xmlWriter.Write ElementString(" store_id", store_id);
xmlWriter.Write ElementString(" api_token", api_token);
xmlWriter.Write StartElement("p urchase");
xmlWriter.Write ElementString(" order_id",
System.Guid.New Guid().ToString ());
xmlWriter.Write ElementString(" amount", amount);
xmlWriter.Write ElementString(" pan",
CCNumberBox.Tex t.Trim());
xmlWriter.Write ElementString(" expdate",
MonthList.Selec tedValue + YearList.Select edValue);
xmlWriter.Write ElementString(" crypt_type", crypt);
xmlWriter.Write EndElement();
xmlWriter.Write EndElement();
xmlWriter.Write EndDocument();
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.Crea te("http://example.com/2005/04/receiveXML.aspx ");
httpRequest.Met hod = "POST";
// now use XmlWriter on httpRequest.Get RequestStream
// to write out the XML
// then use
HttpWebResponse httpResponse = (HttpWebRespons e)
httpRequest.Get Response();
// now use properties/method of the response to read out
// headers or the response stream
// for instance
XmlDocument responseXML = new XmlDocument();
responseXML.loa d(httpResponse. GetResponseStre am());
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/