Skip Navigation

C#

using System; using System.IO; using System.Net; using System.Xml; using System.Web; using System.Text; class SDKPost { private const string C_ATHOC_SERVER_LOCATION = "http://athoc.server.com"; private const string C_EXTENSION_LOCATION = "/sdk/listener/listen.asp"; private const string C_PROXY_HOST = ""; private const int C_PROXY_PORT = 80; public static void Main() { //this is our string URL String uri = new StringBuilder(C_ATHOC_SERVER_LOCATION).Append(C_EXTENSION_LOCATION).ToString(); //build AtHoc Sdk authentication and user sync request xml String postData = new StringBuilder("<AtHocSdk>") .Append("<client>2010110</client>") .Append("<validation>") .Append("<username>SDK Username</username>") .Append("<password>SDK Password</password>") .Append("</validation>") .Append("<payload type='USER-SYNC'>") .Append("<userSynchronization>") .Append("<mid>johnsmith</mid>") .Append("</userSynchronization>") .Append("</payload>") .Append("</AtHocSdk>").ToString(); String userProfileXML = PostURL(uri, false, postData); System.Console.WriteLine(userProfileXML); } // PostURL – posts postData to p_PageURL, while considering p_useProxy // returns the document from the posted to URL public static String PostURL(String p_PageURL, bool p_useProxy, String postData) { String strXML = ""; try { postData = "data=" + HttpUtility.UrlEncode(postData); byte[] data = Encoding.ASCII.GetBytes(postData); HttpWebRequest l_WebReq = (HttpWebRequest)WebRequest.Create(p_PageURL); l_WebReq.Method = "POST"; l_WebReq.ContentLength = data.Length; l_WebReq.ContentType = "application/x-www-form-urlencoded"; if (p_useProxy) { WebProxy l_proxyObject = new WebProxy(C_PROXY_HOST, C_PROXY_PORT); l_WebReq.Proxy = l_proxyObject; } Stream newStream = l_WebReq.GetRequestStream(); try { // Send the data. newStream.Write(data, 0, data.Length); } catch (Exception e) { return e.Message; } finally { newStream.Close(); } HttpWebResponse l_WebRes = (HttpWebResponse)l_WebReq.GetResponse(); StreamReader l_sr = new StreamReader(l_WebRes.GetResponseStream(), Encoding.ASCII); strXML = l_sr.ReadToEnd(); l_sr.Close(); } catch (Exception err) { strXML = "WEB PAGE ERROR : in RetrieveWebPage URL = " + p_PageURL + " - " + err.ToString(); } return strXML; } // of PostURL }