Exemplo n.º 1
0
        //      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);
        }
Exemplo n.º 2
0
        //      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;
        }