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