Exemplo n.º 1
0
 public static bool Save(string fullName, out ResponseMessage responseMessage)
 {
     Uri uri = new Uri(String.Format("{0}/HolidayWork/SaveConfirm?fullName={1}", OdataServiceUri, fullName));
     string json = String.Empty;//JsonConvert.SerializeObject(fullName);
     bool result = PostJson(uri, json, out responseMessage);
     return result;
 }
Exemplo n.º 2
0
        protected static bool PostJson(Uri uri, string json, out ResponseMessage responseMessage)
        {
            var request = (HttpWebRequest)WebRequest.Create(uri);
            CredentialCache cc = new CredentialCache();
            cc.Add(uri, "NTLM", CredentialCache.DefaultNetworkCredentials);
            request.Credentials = cc;
            request.ContentType = "text/json";
            request.Method = "POST";

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var response = (HttpWebResponse)request.GetResponse();
            using (var streamReader = new StreamReader(response.GetResponseStream()))
            {
                string responseContent = streamReader.ReadToEnd();
                responseMessage = JsonConvert.DeserializeObject<ResponseMessage>(responseContent);
            }

            return response.StatusCode == HttpStatusCode.Created;
        }