// internal const string SubDomain = "utc"; // internal const string ApiToken = "palm428naval"; public static UtcResponse GetUtcRequest(UtcGetRequest getRequest) { UtcResponse retVal = new UtcResponse(); string url = getRequest.Url + getRequest.Action; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); //CredentialCache myCache = new CredentialCache(); //myCache.Add(new Uri(url), "Basic", new NetworkCredential(ApiToken, "")); //myReq.Credentials = myCache; myReq.ContentType = "application/xml"; myReq.ContentLength = 0; myReq.Method = "GET"; try { HttpWebResponse wr = (HttpWebResponse)myReq.GetResponse(); retVal.StatusCode = (int)wr.StatusCode; Stream receiveStream = wr.GetResponseStream(); StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); retVal.Xml = reader.ReadToEnd(); retVal.Success = true; } catch (WebException ex) { HttpWebResponse exResponse = (HttpWebResponse)ex.Response; retVal.StatusCode = (int)exResponse.StatusCode; retVal.ErrorMessage = ex.Message; } return(retVal); }
public static UtcResponse PostUtcRequest(UtcPostRequest postRequest) { UtcResponse retVal = new UtcResponse(); string url = postRequest.Url + postRequest.Action; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); //CredentialCache myCache = new CredentialCache(); //myCache.Add(new Uri(url), "Basic", new NetworkCredential(ApiToken, "")); //myReq.Credentials = myCache; // byte[] byteArray = Encoding.UTF8.GetBytes(putRequest.XmlDoc.InnerXml); byte[] byteArray = Encoding.UTF8.GetBytes(postRequest.XmlDoc); myReq.ContentType = "application/xml"; myReq.ContentLength = byteArray.Length; myReq.Method = "POST"; Stream dataStream = myReq.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); try { HttpWebResponse wr = (HttpWebResponse)myReq.GetResponse(); retVal.StatusCode = (int)wr.StatusCode; Stream receiveStream = wr.GetResponseStream(); StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); retVal.Xml = reader.ReadToEnd(); retVal.Success = true; } catch (WebException ex) { HttpWebResponse exResponse = (HttpWebResponse)ex.Response; retVal.StatusCode = (int)exResponse.StatusCode; retVal.ErrorMessage = ex.Message; } return(retVal); }
public static UtcResponse PutUtcRequest(UtcPutRequest putRequest) { UtcResponse retVal = new UtcResponse(); string url = putRequest.Url + putRequest.Action; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); //CredentialCache myCache = new CredentialCache(); //myCache.Add(new Uri(url), "Basic", new NetworkCredential(ApiToken, "")); //myReq.Credentials = myCache; // byte[] byteArray = Encoding.UTF8.GetBytes(putRequest.XmlDoc.InnerXml); byte[] byteArray = Encoding.UTF8.GetBytes(putRequest.XmlDoc); myReq.ContentType = "application/xml"; myReq.ContentLength = byteArray.Length; myReq.Method = "POST"; Stream dataStream = myReq.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); try { HttpWebResponse wr = (HttpWebResponse)myReq.GetResponse(); retVal.StatusCode = (int)wr.StatusCode; Stream receiveStream = wr.GetResponseStream(); StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); retVal.Xml = reader.ReadToEnd(); retVal.Success = true; } catch (WebException ex) { HttpWebResponse exResponse = (HttpWebResponse)ex.Response; retVal.StatusCode = (int)exResponse.StatusCode; retVal.ErrorMessage = ex.Message; } return retVal; }
// internal const string SubDomain = "utc"; // internal const string ApiToken = "palm428naval"; public static UtcResponse GetUtcRequest(UtcGetRequest getRequest) { UtcResponse retVal = new UtcResponse(); string url = getRequest.Url + getRequest.Action; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); //CredentialCache myCache = new CredentialCache(); //myCache.Add(new Uri(url), "Basic", new NetworkCredential(ApiToken, "")); //myReq.Credentials = myCache; myReq.ContentType = "application/xml"; myReq.ContentLength = 0; myReq.Method = "GET"; try { HttpWebResponse wr = (HttpWebResponse)myReq.GetResponse(); retVal.StatusCode = (int)wr.StatusCode; Stream receiveStream = wr.GetResponseStream(); StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); retVal.Xml = reader.ReadToEnd(); retVal.Success = true; } catch (WebException ex) { HttpWebResponse exResponse = (HttpWebResponse)ex.Response; retVal.StatusCode = (int)exResponse.StatusCode; retVal.ErrorMessage = ex.Message; } return retVal; }