Esempio n. 1
0
        public static bool UploadSWEntry(AddSoftware lSoftware)
        {
            try
            {
                JavaScriptSerializer ser = new JavaScriptSerializer();
                //oClient.DefaultRequestHeaders.Add("AuthenticatedToken", Token);
                //oClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));
                HttpContent oCont = new StringContent(ser.Serialize(lSoftware), Encoding.UTF8, contentType);

                var response = oClient.PostAsync(sURL + "/rest/UploadSWEntry", oCont);
                response.Wait(10000);

                if (response.Result.StatusCode == HttpStatusCode.OK)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch { }

            return(false);
        }
Esempio n. 2
0
        public static bool UploadSWEntry(AddSoftware lSoftware)
        {
            try
            {
                string sData = DataContractSerializeObject <AddSoftware>(lSoftware);

                byte[]         bytes   = Encoding.UTF8.GetBytes(sData);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL + "/rest/UploadSWEntry");
                request.Method        = "POST";
                request.ContentLength = bytes.Length;
                request.Headers.Add("AuthenticatedToken:" + Token);
                request.ContentType = "application/xml";

                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(bytes, 0, bytes.Length);
                }

                HttpWebResponse response    = (HttpWebResponse)request.GetResponse();
                Stream          resStream   = response.GetResponseStream();
                StreamReader    rdStreamRdr = new StreamReader(resStream);
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    string message = String.Format("POST Failed. Received HTTP {0}",
                                                   response.StatusCode);
                    throw new ApplicationException(message);
                }
                else
                {
                    string message = rdStreamRdr.ReadToEnd();
                    var    oResult = DataContractDeSerializeObject <bool>(message);
                    return(oResult);
                }
            }
            catch { }

            return(false);
        }