locked
Will this code work for Any web api for POST,PUT,DELETE,MERGE,OPTIONS,HEAD ,GET RRS feed

  • Question

  • User-148788041 posted

    hI,

    Will this code work for any Web Api for  POST,PUT,DELETE,MERGE,OPTIONS,HEAD ,GET

            #region HTTP Request
            public async Task<object> HttpRequest(WebProperties mp)
            {
                object dicGetHttpRequest = null;
                string strResult, strJson = string.Empty;
                StreamReader rd;
                
                String strUrl = mp.EndPoint;
                //Regex to check if string starts with http or https
                Regex rgx = new Regex(@"^(http|https|www)://.*$");
                //Regex to remove the text content
                if (rgx.IsMatch(strUrl))
                {
                    ////do your task here
                    //Console.WriteLine("Url Starts with Https,Http,www");
    
                    if (strUrl.Contains("https"))
                    {
    
                        HttpWebRequest request = System.Net.WebRequest.Create(mp.EndPoint) as System.Net.HttpWebRequest;
    
                        try
                        {
    
                            if (mp.ActionName.ToLower() == "get")
                            {
                                var _action = mp.EndPoint;
                                if (mp.ActionName.ToLower() != "")
                                {
    
                                    dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
    
                                }
                            }
    
                            if (mp.ActionName.ToLower() == "post")
                            {
                                var _action = mp.EndPoint + "/" + mp.ActionName;
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                                //HttpCallWebService(mp);
                            }
                            if (mp.ActionName.ToLower() == "put")
                            {
                                var _action = mp.EndPoint + "/" + mp.ActionName;
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
    
                            }
                            if (mp.ActionName.ToLower() == "delete")
                            {
                                var _action = mp.EndPoint + "/" + mp.ActionName;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
    
                            }
                            if (mp.ActionName.ToLower() == "head")
                            {
                                var _action = mp.EndPoint + "/" + mp.ActionName;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                            }
                            if (mp.ActionName.ToLower() == "options")
                            {
                                var _action = mp.EndPoint + "/" + mp.ActionName;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                            }
                            if (mp.ActionName.ToLower() == "patch")
                            {
                                var _action = mp.EndPoint + "/" + mp.ActionName;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                            }
                            if (mp.ActionName.ToLower() == "merge")
                            {
                                var _action = mp.EndPoint + "/" + mp.ActionName;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                            }
    
                            return dicGetHttpRequest;
                        }
                        catch (Exception Ex)
                        {
                            //object dicGetHttpRequest = null;
    
    
                            //dicHttpRequest = "Error in processing data";
    
                            //dicGetHttpRequest.Add("status", Ex.Message);
                            //dicGetHttpRequest.Add("error", "");
    
                            //dicGetHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
    
                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", Ex.Message + Environment.NewLine + Ex.StackTrace);
                        }
    
    
                    }
    
    
                    if (strUrl.Contains("http"))
                    {
                        HttpWebRequest request = System.Net.WebRequest.Create(mp.EndPoint) as System.Net.HttpWebRequest;
    
                        try
                        {
    
                            if (mp.ActionName.ToLower() == "get" || mp.ActionName.ToLower() == "head")
                            {
                                var _action = mp.EndPoint;
                                if (mp.ActionName.ToLower() != "")
                                {
    
                                    dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
    
                                }
                            }
    
                            if (mp.ActionName.ToLower() == "post")
                            {
                                var _action = mp.EndPoint;
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                                //HttpCallWebService(mp);
                            }
                            if (mp.ActionName.ToLower() == "put")
                            {
                                var _action = mp.EndPoint + mp.MethodName;
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
    
                            }
                            if (mp.ActionName.ToLower() == "delete")
                            {
                                var _action = mp.EndPoint;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
    
                            }
                            if (mp.ActionName.ToLower() == "head")
                            {
                                var _action = mp.EndPoint;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                            }
                            if (mp.ActionName.ToLower() == "options")
                            {
                                var _action = mp.EndPoint;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                            }
                            if (mp.ActionName.ToLower() == "patch")
                            {
                                var _action = mp.EndPoint;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                            }
                            if (mp.ActionName.ToLower() == "merge")
                            {
                                var _action = mp.EndPoint;
    
                                dicGetHttpRequest = await HttpResponseAsync(request, _action, mp);
                            }
    
                            return dicGetHttpRequest;
                        }
                        catch (Exception Ex)
                        {
                            
    
                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", Ex.Message + Environment.NewLine + Ex.StackTrace);
                        }
    
    
                    }
    
    
    
                }
    
                return dicGetHttpRequest;
    
            }
            public async Task<object> HttpResponseAsync(HttpWebRequest strRequest, string strAction, WebProperties mp)
            {
                Api webApi = new Api();
                string responseStr = string.Empty;
                object dicHttpRequest = null;
                XmlDocument cs = new XmlDocument();
                // string strFormatString = Uri.EscapeUriString(strAction);
                string httpResult = null;
    
                //GET OPERATION
                if (mp.ActionName.ToLower() == "get" || mp.ActionName.ToLower() == "head")
                {
    
                    HttpClient client = new HttpClient();
                    string strFileExtension = Path.GetExtension(mp.InputString);
                    if (mp.AcceptFormat.ToLower().Trim()=="text/xml" && strFileExtension.Trim() == ".xml")
                    {
                        if (Validate(mp.InputString))
                        {
    
                            var xhr = new XMLHttpRequest();
                            
                            //xhr.Open(XMLHttpRequest.EnumMethod.Get, mp.EndPoint, "", "");
                            //xhr.Send(mp.InputString);
                            //var result = xhr.Status;
                            //if (xhr.Readystate != "")
    
                            //{
                            //    if (result == 200)
                            //    {
                            //        string response1 = xhr.ResponseText;
                            //    }
                            //}
    
                            try
                            {
                                string xmlString = File.ReadAllText(mp.InputString);
                                using (MemoryStream memStream = new MemoryStream())
    
                                   
                                using (XmlReader xmlReader = XmlReader.Create(new StringReader(xmlString)))
                                using (XmlWriter xmlWriter = XmlWriter.Create(memStream))
                                {
                                    // write the returned xml into a memory stream
                                    xmlWriter.WriteNode(xmlReader, true);
                                    xmlWriter.Flush();
                                    // set position back in memory stream to enable reading data
                                    memStream.Position = 0;
                                    // create a web request
                                    HttpWebRequest requestRead = (HttpWebRequest)HttpWebRequest.Create(mp.EndPoint);
                                    // set content length BEFORE you start writing the content stream
                                    requestRead.ContentLength = memStream.Length;
                                    // Get the content stream and writ the xml into
                                    Stream requestStream = requestRead.GetRequestStream();
                                    byte[] buffer = new byte[1024];
                                    int length;
                                    while (0 != (length = memStream.Read(buffer, 0, buffer.Length)))
                                    {
                                        requestStream.Write(buffer, 0, length);
                                    }
                                    // Get the response stream and do whatever you want
                                    WebResponse responseRead = requestRead.GetResponse();
                                    Stream responseStream = responseRead.GetResponseStream();
                                }
    
    
    
    
                                return dicHttpRequest;
    
    
    
                            }
                            catch (Exception Ex)
                            {
                                ErrorLogger.dologging("XmlManipulator", "HttpResponseAsyncs", "Error in getting data by using XML");
                            }
    
    
                        }
                    }
                        if (mp.AcceptFormat.ToLower().Trim() == "application/json")
                        {
    
                            if (IsValidJson(mp.InputString))
                            {
    
                               
    
    
                                var jObject2 = Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(mp.InputString),
                                new Newtonsoft.Json.JsonSerializerSettings
                                {
                                    DateParseHandling = Newtonsoft.Json.DateParseHandling.DateTimeOffset
                                });
    
    
    
    
    
                                //var p = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(File.ReadAllText(mp.JsonString), new TrimmingConverter());
                                JObject json = JObject.Parse(jObject2.ToString());
    
                                JToken user_info = JObject.Parse(json.ToString().Trim());
    
                                string strValuePassed = user_info.Root.ToString().Trim();
                                string strReplace = strValuePassed.Replace(": ", "=").Trim();
                                string strNew = strReplace.Replace(" ", string.Empty);
    
                                JObject jobj = JObject.Parse(jObject2.ToString());
                                string str = string.Empty;
                                foreach (var item in jobj)
                                {
                                    //use item.Value.Type==JtokenType.Integer   to check whertther item.Value is of Type integer or not
                                    str += item.Key + "=" + (item.Value.Type == JTokenType.Integer ? item.Value : ("'" + item.Value + "'")) + "&";
    
                                }
                                string strFinalString = str.Remove(str.Length - 1);
                                // Console.WriteLine(strFinalString);
    
                                string strValueToBePassed = strNew.Replace('"', ' ').Trim().Replace(" ", string.Empty);
    
    
    
    
                                ////var urls = $"http://10.110.48.90:89/WebApi/api/DeleteEmployee?id={user_info["id"]}";
                                //string fullAddress =$"http://10.110.48.90:89/WebApi/api/DeleteEmployee?id={user_info["id"]}'";
    
    
    
    
    
    
                                string strArgument = "";
                                // HttpClient client = new HttpClient();
                                client.BaseAddress = new Uri(mp.EndPoint);
                                client.DefaultRequestHeaders.Accept.Clear();
                                //    HttpResponseMessage response = client.DeleteAsync("?id=10013").Result;
    
                                client.DefaultRequestHeaders.Clear();
                                client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("nl-NL"));
    
                                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                                //  string token = param.token.Value;
                                // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
    
                                //HttpResponseMessage response = client.GetAsync("?" + strFinalString + "").Result;
                                foreach (var item in jobj)
                                {
                                    //use item.Value.Type==JtokenType.Integer   to check whertther item.Value is of Type integer or not
                                    str += item.Key + "=" + (item.Value.Type == JTokenType.Integer ? item.Value : ("'" + item.Value + "'")) + "&";
    
                                    strArgument = item.Value.ToString();
    
                                }
    
    
                                //  HttpResponseMessage response = await client.GetAsync(string.Concat(mp.MethodName, item.Value));
                                //  HttpResponseMessage response = client.GetAsync("?" + strFinalString + "").Result;
                                //"api/DeleteEmployee?id={" + valueGot.ToString() + "}"
                                // HttpResponseMessage response = await client.GetAsync("http://10.110.48.90:89/Employees/GetEmployee?id=10037");
    
                                try
                                {
                                    HttpWebRequest requestGet = (HttpWebRequest)WebRequest.Create(mp.EndPoint + mp.MethodName + "?" + strFinalString + "");
    
                                    HttpWebResponse responseGet = (HttpWebResponse)requestGet.GetResponse();
    
                                    StreamReader srGet = new StreamReader(responseGet.GetResponseStream());
                                    dicHttpRequest = srGet.ReadToEnd();
    
                                }
                                catch (Exception Ex)
                                {
                                    ErrorLogger.dologging("XmlManipulator", "HttpResponseAsyncs", "Error in getting data  by Json.");
                                }
    
                                return dicHttpRequest;
                            }
                        }
    
                        //HttpClient client = new HttpClient();
                        client.BaseAddress = new Uri(strAction);
                        //if (mp.AcceptFormat.ToLower().Trim() == "text/xml")
    
    
                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mp.EndPoint);
                        client.DefaultRequestHeaders.Accept.Clear();
                        HttpWebRequest requestGetAllData = (HttpWebRequest)WebRequest.Create(mp.EndPoint + mp.MethodName);
    
                        HttpWebResponse response = (HttpWebResponse)requestGetAllData.GetResponse();
    
                        StreamReader sr = new StreamReader(response.GetResponseStream());
                        dicHttpRequest = sr.ReadToEnd();
    
    
                        return dicHttpRequest;
    
    
    
                    }
    
                    //POST OPERATION
                    if (mp.ActionName.ToLower() == "post")
                    {
    
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "text/xml")
                            {
                                if (Validate(mp.InputString))
                                {
                                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mp.EndPoint);
                                    byte[] bytes;
                                    //    bytes = System.Text.Encoding.ASCII.GetBytes(mp.XMLString);
    
                                    byte[] byteArray = Encoding.UTF8.GetBytes(mp.InputString);
                                    request.ContentType = "text/xml; encoding='utf-8'";
                                    request.ContentLength = byteArray.Length;
                                    request.Method = mp.ActionName;
                                    Stream requestStream = request.GetRequestStream();
                                    requestStream.Write(byteArray, 0, byteArray.Length);
                                    requestStream.Close();
                                    HttpWebResponse response;
                                    response = (HttpWebResponse)request.GetResponse();
                                    if (response.StatusCode == HttpStatusCode.OK)
                                    {
                                        Stream responseStream = response.GetResponseStream();
                                        responseStr = new StreamReader(responseStream).ReadToEnd();
                                        responseStream.Dispose();
                                        var content = responseStr;
    
                                        // Parse 1 Product from the content
                                        object ItemsSet = JsonConvert.DeserializeObject<dynamic>(content);
                                        dicHttpRequest = ItemsSet;
    
                                    }
    
                                    else
                                    {
    
                                        Stream responseStream = response.GetResponseStream();
                                        responseStr = new StreamReader(responseStream).ReadToEnd();
                                        responseStream.Dispose();
                                        var content = responseStr;
    
                                        // Parse 1 Product from the content
                                        object ItemsSet = JsonConvert.DeserializeObject<dynamic>(content);
                                        dicHttpRequest = ItemsSet;
    
                                    }
    
                                    return dicHttpRequest;
    
                                }
    
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in posting data  by XML.");
                        }
    
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "application/json")
                            {
    
                                try
                                {
                                    if (IsValidJson(mp.InputString))
                                    {
                                        var httpHost = new HttpClient();
    
                                        httpHost.BaseAddress = new Uri(mp.EndPoint);
                                        httpHost.DefaultRequestHeaders.Accept.Clear();
    
                                        httpHost.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                        var jObject2 = Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(mp.InputString),
                            new Newtonsoft.Json.JsonSerializerSettings
                            {
                                DateParseHandling = Newtonsoft.Json.DateParseHandling.DateTimeOffset
                            });
    
    
    
    
    
                                        //var p = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(File.ReadAllText(mp.JsonString), new TrimmingConverter());
                                        JObject json = JObject.Parse(jObject2.ToString());
                                        var content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
                                        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                                        var result = httpHost.PostAsync(mp.MethodName, content).Result;
    
                                        //string serilized = JsonConvert.SerializeObject(File.ReadAllText(mp.JsonString));
                                        //var inputMessage = new HttpRequestMessage
                                        //{
                                        //    Content = new StringContent(serilized, Encoding.UTF8, "application/json")
                                        //};
    
    
    
                                        //httpHost.BaseAddress = new Uri(mp.EndPoint);
                                        //httpHost.DefaultRequestHeaders.Accept.Clear();
    
                                        //httpHost.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                                        //var content = new StringContent(mp.JsonString.ToString(), Encoding.UTF8, "application/json");
                                        //HttpResponseMessage response = httpHost.PostAsJsonAsync(mp.EndPoint+mp.MethodName, content).Result;
    
                                        //HttpResponseMessage response = await httpHost.PostAsync(mp.MethodName, content);
    
                                        //inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                        // HttpResponseMessage response = httpHost.PostAsync(mp.MethodName, inputMessage.Content).Result;
    
    
    
                                        //httpHost.BaseAddress = new Uri(mp.EndPoint);
                                        //httpHost.DefaultRequestHeaders.Accept.Clear();
                                        //httpHost.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                                        //dynamic strReadValues = File.ReadAllText(mp.JsonString);
                                        //var content = new StringContent(JsonConvert.SerializeObject(strReadValues), Encoding.UTF8, "application/json");
    
                                        //var  response = await httpHost.PostAsJsonAsync(mp.MethodName, content);
    
    
    
                                        if (result.IsSuccessStatusCode)
                                        {
    
                                            var postData = "Data are Saved to database";
                                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data are Saved to database");
    
                                            dicHttpRequest = postData;
                                            //var result = response.Content.ReadAsAsync<IAsyncResult>().Result;
    
                                            //dicHttpRequest.Add("status", "The POST response for JSON From HttpRequest is " + result);
    
                                            //dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                        }
                                        else
                                        {
                                            var postData = "Data are not Saved to database";
                                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data are not Saved to database");
    
                                            dicHttpRequest = postData;
                                            //dicHttpRequest.Add("status", "The POST  response for JSON From HttpRequest is " + result);
    
                                            //dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                        }
                                        //string myJson =  jObject2.ToString();
                                        //string strs = '"' + myJson + '"';
                                        //    using (var client = new HttpClient())
                                        //    {
    
                                        //    //    var response = await client.PostAsync(mp.EndPoint, new StringContent(jObject2.ToString(), Encoding.UTF8, "application/json"));
                                        //    var response = await client.PostAsync(mp.EndPoint,  new StringContent(strs, Encoding.UTF8, "application/json"));
                                        //}
                                        //System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                                        //Byte[] byteArray = encoding.GetBytes(mp.JsonString);
    
                                        //request.ContentLength = byteArray.Length;
                                        //request.ContentType = @"application/json";
    
                                        //using (Stream dataStream = request.GetRequestStream())
                                        //{
                                        //    dataStream.Write(byteArray, 0, byteArray.Length);
    
    
                                        //}
                                        //long length = 0;
                                        //try
                                        //{
                                        //    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                                        //    {
                                        //        length = response.ContentLength;
    
                                        //        dicHttpRequest.Add("status", "The POST response for JSON From HttpRequest is " + request.GetResponse());
    
                                        //        dicHttpRequest.Add("statuscode", length.ToString());
    
                                        //    }
                                        //}
                                        //catch (WebException ex)
                                        //{
                                        //    // Log exception and throw as for GET example above
                                        //}
                                    }
                                }
    
                                catch (WebException ex)
                                {
                                    using (var stream = ex.Response.GetResponseStream())
                                    using (var reader = new StreamReader(stream))
                                    {
                                        var postData = "Error in Saving data to database";
                                        ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Error in Saving data to database");
    
                                        dicHttpRequest = postData;
                                        //Console.WriteLine(reader.ReadToEnd());
                                        //dicHttpRequest.Add("status", "The POST response for JSON From HttpRequest is " + reader.ReadToEnd());
    
                                        //dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                    }
                                }
                                catch (Exception ex)
                                {
                                    // Something more serious happened
                                    // like for example you don't have network access
                                    // we cannot talk about a server exception here as
                                    // the server probably was never reached
                                }
    
                                // Log exception and throw as for GET example above
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in posting data  by Json.");
                        }
                        return dicHttpRequest;
    
    
    
                    }
    
                    //PUT OR PATCH OPERATION
                    if (mp.ActionName.ToLower() == "put" || mp.ActionName.ToLower() == "patch" || mp.ActionName.ToLower() == "merge")
                    {
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "text/xml")
                            {
                                if (Validate(mp.InputString))
                                {
                                    //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mp.EndPoint);
                                    string strXmlFile = Path.GetFullPath(mp.InputString);
                                    XDocument xmlDoc = XDocument.Load(strXmlFile);
                                    foreach (var node in xmlDoc.DescendantNodes().OfType<XText>())
                                    {
                                        var value = node.Value.Trim();
    
                                        if (!string.IsNullOrEmpty(value))
                                        {
                                            Console.WriteLine(value);
                                            //some code...
                                        }
                                    }
    
    
    
                                    //JObject json = JObject.Parse(jObject2.ToString());
    
                                    //string serilized = JsonConvert.SerializeObject(File.ReadAllText(mp.JsonString));
                                    //var inputMessage = new HttpRequestMessage
                                    //{
                                    //    Content = new StringContent(serilized, Encoding.UTF8, "application/json")
                                    //};
                                    var httpHost = new HttpClient();
                                    httpHost.BaseAddress = new Uri(mp.EndPoint);
                                    //inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                    //HttpResponseMessage message = httpHost.PostAsXmlAsync(mp.MethodName,mp.XMLString).Result;
                                    using (HttpResponseMessage response = httpHost.PostAsXmlAsync<string>(mp.ActionName, mp.InputString).Result)
                                    {
    
                                        var result = response.EnsureSuccessStatusCode();
    
                                        if (result.IsSuccessStatusCode)
                                        {
                                            var postData = "Data are updated to database";
                                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data are updated to database");
    
                                            dicHttpRequest = postData;
                                            //dicHttpRequest.Add("status", "The PUT or PATCH  response for XML From HttpRequest is " + result);
    
                                            //dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                        }
                                        else
                                        {
    
                                            var postData = "Data are not updated to database";
                                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data are  not updated to database");
    
                                            dicHttpRequest = postData;
                                            //dicHttpRequest.Add("status", "The PUT  or PATCH  response for XML From HttpRequest is " + result);
    
                                            //dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                        }
                                    }
    
                                    return dicHttpRequest;
    
                                }
    
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in updating data  by XML.");
                        }
    
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "application/json")
                            {
    
                                if (IsValidJson(mp.InputString))
                                {
                                    var jObject2 = Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(mp.InputString),
                             new Newtonsoft.Json.JsonSerializerSettings
                             {
                                 DateParseHandling = Newtonsoft.Json.DateParseHandling.DateTimeOffset
                             });
    
    
    
    
    
                                    //var p = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(File.ReadAllText(mp.JsonString), new TrimmingConverter());
                                    JObject json = JObject.Parse(jObject2.ToString());
    
                                    JToken user_info = JObject.Parse(json.ToString().Trim());
    
                                    string strValuePassed = user_info.Root.ToString().Trim();
                                    string strReplace = strValuePassed.Replace(": ", "=").Trim();
                                    string strNew = strReplace.Replace(" ", string.Empty);
    
                                    JObject jobj = JObject.Parse(jObject2.ToString());
                                    string str = string.Empty;
                                    foreach (var item in jobj)
                                    {
                                        //use item.Value.Type==JtokenType.Integer   to check whertther item.Value is of Type integer or not
                                        str += item.Key + "=" + (item.Value.Type == JTokenType.Integer ? item.Value : ("'" + item.Value + "'")) + "&";
    
                                    }
    
                                    string serilized = JsonConvert.SerializeObject(File.ReadAllText(mp.InputString));
                                    var inputMessage = new HttpRequestMessage
                                    {
                                        Content = new StringContent(serilized, Encoding.UTF8, "application/json")
                                    };
    
                                    var httpHost = new HttpClient();
                                    httpHost.BaseAddress = new Uri(mp.EndPoint);
                                    inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                    HttpResponseMessage message = httpHost.PutAsync(mp.MethodName, inputMessage.Content).Result;
                                    //string strFinalString = str.Remove(str.Length - 1);
                                    //Console.WriteLine(strFinalString);
                                    //var httpHost = new HttpClient();
    
                                    //httpHost.BaseAddress = new Uri(mp.EndPoint);
                                    ////serialize your json using newtonsoft json serializer then add it to the StringContent
                                    //var content = new StringContent(mp.JsonString, Encoding.UTF8, "application/json");
                                    //httpHost.DefaultRequestHeaders.Accept.Clear();
                                    //httpHost.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                                    //method address would be like api/callUber:SomePort for example
                                    using (HttpResponseMessage response = httpHost.PutAsJsonAsync(mp.MethodName, json).Result)
                                    {
    
                                        var result = response.EnsureSuccessStatusCode();
    
                                        if (result.IsSuccessStatusCode)
                                        {
                                            var postData = "Data are  updated to database";
    
                                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data are updated to database");
                                            dicHttpRequest = postData;
                                            //dicHttpRequest.Add("status", "The PUT or PATCH or MERGE response for JSON From HttpRequest is " + result);
    
                                            //dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                        }
                                        else
                                        {
                                            var postData = "Data are not updated to database";
                                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data are not updated to database");
    
                                            dicHttpRequest = postData;
                                            //dicHttpRequest.Add("status", "The PUT  or PATCH or MERGE  response for JSON From HttpRequest is " + result);
    
                                            //dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                        }
                                    }
    
                                    //var result = await httpHost.PostAsync(mp.MethodName, content);
                                    //string resultContent = await result.Content.ReadAsStringAsync();
    
    
                                    httpHost.Dispose();
                                    return dicHttpRequest;
                                }
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in updating data  by Json.");
                        }
                    }
    
                    //DELETE OPERATIONS
                    if (mp.ActionName.ToLower() == "delete")
                    {
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "text/xml")
                            {
                                if (Validate(mp.InputString))
                                {
                                    //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mp.EndPoint);
                                    //  byte[] bytes;
                                    //    bytes = System.Text.Encoding.ASCII.GetBytes(mp.XMLString);
    
                                    //byte[] byteArray = Encoding.UTF8.GetBytes(mp.XMLString);
                                    //request.ContentType = mp.AcceptFormat;
                                    //request.ContentLength = byteArray.Length;
                                    //request.Method = mp.MethodName;
                                    //Stream requestStream = request.GetRequestStream();
                                    //requestStream.Write(byteArray, 0, byteArray.Length);
                                    //requestStream.Close();
                                    //HttpWebResponse response;
                                    //response = (HttpWebResponse)request.GetResponse();
    
                                    HttpClient client = new HttpClient();
                                    client.BaseAddress = new Uri(mp.EndPoint);
                                    client.DefaultRequestHeaders.Accept.Clear();
                                    XmlTextReader textReader = new XmlTextReader(mp.InputString);
                                    textReader.Read();
    
                                    // If the node has value  
                                    while (textReader.Read())
                                    {
                                        // Move to fist element  
                                        textReader.MoveToElement();
                                        Console.WriteLine("XmlTextReader Properties Test");
                                        Console.WriteLine("===================");
                                        // Read this element's properties and display them on console  
                                        Console.WriteLine("Name:" + textReader.Name);
                                        Console.WriteLine("Base URI:" + textReader.BaseURI);
                                        Console.WriteLine("Local Name:" + textReader.LocalName);
                                        Console.WriteLine("Attribute Count:" + textReader.AttributeCount.ToString());
                                        Console.WriteLine("Depth:" + textReader.Depth.ToString());
                                        Console.WriteLine("Line Number:" + textReader.LineNumber.ToString());
                                        Console.WriteLine("Node Type:" + textReader.NodeType.ToString());
                                        Console.WriteLine("Attribute Count:" + textReader.Value.ToString());
                                    }
    
                                    HttpResponseMessage response = client.DeleteAsync(mp.ActionName + "/" + textReader.Name).Result;
                                    if (response.StatusCode == HttpStatusCode.OK)
                                    {
                                        var postData = "Data are Deleted from database";
                                        ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data are Deleted from database");
    
                                        dicHttpRequest = postData;
    
                                        //dicHttpRequest.Add("status", "The DELETE response for XML From HttpRequest is " + responseStr);
    
                                        //dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                    }
                                    else
                                    {
    
                                        var postData = "Data could not be delete from database";
                                        ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data could not be delete from database");
    
                                        dicHttpRequest = postData;
                                        //dicHttpRequest.Add("status", "The DELETE response for XML From HttpRequest is " + responseStr);
    
                                        //dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                    }
                                    return dicHttpRequest;
    
    
    
                                }
    
    
                                //var response = client.DeleteAsync("api/Api/10").Result;    
                                //var response = client.DeleteAsync(mp.SoapUri).Result;
                                //if (response.IsSuccessStatusCode)
                                //{
                                //    //  Console.Write("Success");    
                                //    dicHttpRequest.Add("status", "Deleted successfully.");
    
                                //    dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                //}
                                //else
                                //{
                                //    //Console.Write("Error");    
                                //    dicHttpRequest.Add("status", "Failed to Delete the record.");
    
                                //    dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                //}
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in deleting data  by XML.");
                        }
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "application/json")
                            {
    
                                if (IsValidJson(mp.InputString))
                                {
    
    
    
                                    var jObject2 = Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(mp.InputString),
                                    new Newtonsoft.Json.JsonSerializerSettings
                                    {
                                        DateParseHandling = Newtonsoft.Json.DateParseHandling.DateTimeOffset
                                    });
    
    
    
    
    
                                    //var p = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(File.ReadAllText(mp.JsonString), new TrimmingConverter());
                                    JObject json = JObject.Parse(jObject2.ToString());
    
                                    JToken user_info = JObject.Parse(json.ToString().Trim());
    
                                    string strValuePassed = user_info.Root.ToString().Trim();
                                    string strReplace = strValuePassed.Replace(": ", "=").Trim();
                                    string strNew = strReplace.Replace(" ", string.Empty);
    
                                    JObject jobj = JObject.Parse(jObject2.ToString());
                                    string str = string.Empty;
                                    foreach (var item in jobj)
                                    {
                                        //use item.Value.Type==JtokenType.Integer   to check whertther item.Value is of Type integer or not
                                        str += item.Key + "=" + (item.Value.Type == JTokenType.Integer ? item.Value : ("'" + item.Value + "'")) + "&";
    
                                    }
                                    string strFinalString = str.Remove(str.Length - 1);
                                    Console.WriteLine(strFinalString);
    
                                    string strValueToBePassed = strNew.Replace('"', ' ').Trim().Replace(" ", string.Empty);
    
                                    //                                    string json1 = @"{
                                    //              'channel': {
                                    //                'title': 'James Newton-King',
                                    //                'link': 'http://james.newtonking.com',
                                    //                'description': 'James Newton-King\'s blog.',
                                    //                'item': [
                                    //                  {
                                    //                    'title': 'Json.NET 1.3 + New license + Now on CodePlex',
                                    //                    'description': 'Annoucing the release of Json.NET 1.3, the MIT license and the source on CodePlex',
                                    //                    'link': 'http://james.newtonking.com/projects/json-net.aspx',
                                    //                    'categories': [
                                    //                      'Json.NET',
                                    //                      'CodePlex'
                                    //                    ]
                                    //                  },
                                    //                  {
                                    //                    'title': 'LINQ to JSON beta',
                                    //                    'description': 'Annoucing LINQ to JSON',
                                    //                    'link': 'http://james.newtonking.com/projects/json-net.aspx',
                                    //                    'categories': [
                                    //                      'Json.NET',
                                    //                      'LINQ'
                                    //                    ]
                                    //                  }
                                    //                ]
                                    //              }
                                    //            }";
    
    
                                    ////var urls = $"http://10.110.48.90:89/WebApi/api/DeleteEmployee?id={user_info["id"]}";
                                    //string fullAddress =$"http://10.110.48.90:89/WebApi/api/DeleteEmployee?id={user_info["id"]}'";
    
    
    
                                    try
                                    {
    
                                        HttpClient client = new HttpClient();
                                        client.BaseAddress = new Uri(mp.EndPoint);
                                        client.DefaultRequestHeaders.Accept.Clear();
                                        //    HttpResponseMessage response = client.DeleteAsync("?id=10013").Result;
    
                                        HttpResponseMessage response = client.DeleteAsync("?" + strFinalString + "").Result;
    
                                        var result = response.EnsureSuccessStatusCode();
    
                                        if (result.IsSuccessStatusCode)
                                        {
                                            var postData = "Data are Deleted from database";
    
                                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data are Deleted from database");
                                            dicHttpRequest = postData;
                                            //dicHttpRequest.Add("status", "The DELETE response for JSON From HttpRequest is " + result);
    
                                            //dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                        }
                                        else
                                        {
                                            var postData = "Data could not be  Deleted from database";
                                            ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "Data could not be  Deleted from database");
    
                                            dicHttpRequest = postData;
                                            //dicHttpRequest.Add("status", "The DELETE response for JSON From HttpRequest is " + result);
    
                                            //dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                        }
                                        //var request = new HttpRequestMessage(HttpMethod.Delete, mp.EndPoint);
                                        //request.Content = new StringContent(JsonConvert.SerializeObject(mp.JsonString), Encoding.UTF8, "application/json");
                                        //await  client.SendAsync(request);
    
    
                                        //using (HttpResponseMessage response = client.DeleteAsync(mp.EndPoint).Result)
                                        //{
    
                                        //    var result = response.EnsureSuccessStatusCode();
    
                                        //    if (result.IsSuccessStatusCode)
                                        //    {
                                        //        dicHttpRequest.Add("status", "The DELETE response for JSON From HttpRequest is " + result);
    
                                        //        dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                        //    }
                                        //    else
                                        //    {
                                        //        dicHttpRequest.Add("status", "The DELETE response for JSON From HttpRequest is " + result);
    
                                        //        dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                        //    }
                                        //}
                                    }
                                    catch (HttpException Ex)
                                    {
    
                                        // throw Ex;
                                    }
                                    catch (Exception Ex)
                                    {
                                        //  throw Ex;
                                    }
                                    //    HttpResponseMessage response = client.DeleteAsync("?id=user_info["id"]).Result;
    
                                    //string strValuePassed = user_info.First.ToString().Trim();
                                    //string strReplace = strValuePassed.Replace(": ", "=").Trim();
                                    //string strNew = strReplace.Replace(" ", string.Empty);
                                    //string strValueToBePassed = strNew.Replace('"', ' ').Trim().Replace(" ", string.Empty);
    
                                    //string strurl = mp.EndPoint + mp.MethodName + "?".Trim() + strValueToBePassed.Trim() ;
                                    //using (var client = new HttpClient())
                                    //{
                                    //    client.BaseAddress = new Uri("http://10.110.48.90:89/WebApi/");
    
                                    //    //HTTP DELETE
                                    //    long valueGot = 10008;
                                    //    //var deleteTask = client.DeleteAsync("api/DeleteEmployee/" + valueGot.ToString());
                                    //    //deleteTask.Wait();
    
                                    //    HttpResponseMessage response = client.DeleteAsync("api/DeleteEmployee?id={" + valueGot.ToString() +"}").Result;
                                    //    //var result = deleteTask.Result;
                                    //    if (response.IsSuccessStatusCode)
                                    //    {
                                    //        Console.WriteLine("Item Deleted");
                                    //        dicHttpRequest.Add("status", "The item is deleted");
    
                                    //        dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                    //    }
                                    //}
                                    //                        var httpHost = new HttpClient();
                                    //httpHost.BaseAddress = new Uri(strurl);
                                    //httpHost.BaseAddress = new Uri(mp.EndPoint);
    
                                    //WebRequest request = WebRequest.Create(strurl);
                                    //request.Method = "DELETE";
                                    //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                                    //if (response.StatusCode == HttpStatusCode.OK)
                                    //{
                                    //    Console.WriteLine("Item Deleted");
                                    //    dicHttpRequest.Add("status", "The item is deleted");
    
                                    //    dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
    
                                    //}
                                    //else
                                    //{
                                    //    dicHttpRequest.Add("status", "The item could not be deleted");
    
                                    //    dicHttpRequest.Add("statuscode", HttpStatusCode.PreconditionFailed.ToString());
                                    //}
    
    
                                    //// httpHost.Dispose();
                                    // return dicHttpRequest;
                                }
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in deleting data  by Json.");
                        }
                    }
    
                    //HEAD OPERATIONS
                    if (mp.ActionName.ToLower() == "head")
                    {
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "text/xml")
                            {
                                if (Validate(mp.InputString))
                                {
                                    //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mp.EndPoint);
                                    //  byte[] bytes;
                                    //    bytes = System.Text.Encoding.ASCII.GetBytes(mp.XMLString);
    
                                    //byte[] byteArray = Encoding.UTF8.GetBytes(mp.XMLString);
                                    //request.ContentType = mp.AcceptFormat;
                                    //request.ContentLength = byteArray.Length;
                                    //request.Method = mp.MethodName;
                                    //Stream requestStream = request.GetRequestStream();
                                    //requestStream.Write(byteArray, 0, byteArray.Length);
                                    //requestStream.Close();
                                    //HttpWebResponse response;
                                    //response = (HttpWebResponse)request.GetResponse();
    
                                    HttpClient client = new HttpClient();
                                    client.BaseAddress = new Uri(mp.EndPoint);
                                    client.DefaultRequestHeaders.Accept.Clear();
                                    XmlTextReader textReader = new XmlTextReader(mp.InputString);
                                    textReader.Read();
    
                                    // If the node has value  
                                    while (textReader.Read())
                                    {
                                        // Move to fist element  
                                        textReader.MoveToElement();
                                        Console.WriteLine("XmlTextReader Properties Test");
                                        Console.WriteLine("===================");
                                        // Read this element's properties and display them on console  
                                        Console.WriteLine("Name:" + textReader.Name);
                                        Console.WriteLine("Base URI:" + textReader.BaseURI);
                                        Console.WriteLine("Local Name:" + textReader.LocalName);
                                        Console.WriteLine("Attribute Count:" + textReader.AttributeCount.ToString());
                                        Console.WriteLine("Depth:" + textReader.Depth.ToString());
                                        Console.WriteLine("Line Number:" + textReader.LineNumber.ToString());
                                        Console.WriteLine("Node Type:" + textReader.NodeType.ToString());
                                        Console.WriteLine("Attribute Count:" + textReader.Value.ToString());
                                    }
    
                                    HttpResponseMessage response = client.DeleteAsync(mp.MethodName + "/" + textReader.Name).Result;
                                    if (response.StatusCode == HttpStatusCode.OK)
                                    {
                                        var postData = "The HEAD response for XML From HttpRequest is " + responseStr;
    
                                        ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "The HEAD response for XML From HttpRequest is " + responseStr);
                                        dicHttpRequest = postData;
    
                                        //dicHttpRequest.Add("status", "The HEAD response for XML From HttpRequest is " + responseStr);
    
                                        //dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                    }
                                    else
                                    {
    
                                        var postData = "The HEAD response for XML From HttpRequest is " + responseStr;
    
                                        ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "The HEAD response for XML From HttpRequest is " + responseStr);
                                        dicHttpRequest = postData;
                                        //dicHttpRequest.Add("status", "The HEAD response for XML From HttpRequest is " + responseStr);
    
                                        //dicHttpRequest.Add("statuscode", HttpStatusCode.BadRequest.ToString());
                                    }
                                    return dicHttpRequest;
    
    
    
                                }
    
    
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in getting data  by using HEAD Action for the given xml input.");
                        }
    
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "application/json")
                            {
    
                                if (IsValidJson(mp.InputString))
                                {
    
                                    //HttpClient client = new HttpClient();
                                    //client.BaseAddress = new Uri(mp.EndPoint);
                                    //var request = new HttpRequestMessage(HttpMethod.Delete, mp.EndPoint+ mp.MethodName);
                                    //request.Content = new StringContent(JsonConvert.SerializeObject(mp.JsonString), Encoding.UTF8, "application/json");
                                    //await client.SendAsync(request);
    
    
                                    var jObject2 = Newtonsoft.Json.JsonConvert.DeserializeObject(File.ReadAllText(mp.InputString),
                                    new Newtonsoft.Json.JsonSerializerSettings
                                    {
                                        DateParseHandling = Newtonsoft.Json.DateParseHandling.DateTimeOffset
                                    });
    
    
                                    //var p = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(File.ReadAllText(mp.JsonString), new TrimmingConverter());
                                    JObject json = JObject.Parse(jObject2.ToString());
    
                                    JToken user_info = JObject.Parse(json.ToString().Trim());
    
                                    //var urls = $"http://10.110.48.90:89/WebApi/api/DeleteEmployee?id={user_info["id"]}";
                                    string fullAddress = $"http://10.110.48.90:89/WebApi/api/DeleteEmployee?id={user_info["id"]}'";
    
                                    using (var client = new HttpClient())
                                    {
                                        using (var response = client.GetAsync(fullAddress).Result)
                                        {
                                            if (response.IsSuccessStatusCode)
                                            {
                                                var customerJsonString = await response.Content.ReadAsStringAsync();
    
                                                var postData = "The HEAD response for Json is  for HttpRequest is " + customerJsonString;
    
                                                ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "The HEAD response for Json is  for HttpRequest is " + customerJsonString);
                                                dicHttpRequest = postData;
                                                //Console.WriteLine("Item Deleted");
                                                //dicHttpRequest.Add("status", "The item is deleted");
    
                                                //dicHttpRequest.Add("statuscode", HttpStatusCode.OK.ToString());
                                            }
                                            else
                                            {
                                                var customerJsonString = await response.Content.ReadAsStringAsync();
    
                                                var postData = "The HEAD failure response for Json is  for HttpRequest is " + customerJsonString;
    
                                                ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "The HEAD failure response for Json is  for HttpRequest is " + customerJsonString);
                                                dicHttpRequest = postData;
    
                                                //Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                                                //dicHttpRequest.Add("status", "The item could not be deleted");
    
                                                //dicHttpRequest.Add("statuscode", HttpStatusCode.PreconditionFailed.ToString());
                                            }
                                        }
                                    }
    
    
                                }
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in getting data  by using HEAD Action for the given Json input.");
                        }
                    }
    
                    //OPTIONS---
    
                    if (mp.ActionName.ToLower() == "options")
                    {
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "text/xml")
                            {
                                if (Validate(mp.InputString))
                                {
    
                                    HttpClient client = new HttpClient();
                                    client.BaseAddress = new Uri(mp.EndPoint);
                                    client.DefaultRequestHeaders.Accept.Clear();
                                    XmlTextReader textReader = new XmlTextReader(mp.InputString);
                                    textReader.Read();
    
                                    // If the node has value  
                                    while (textReader.Read())
                                    {
    
                                    }
    
                                    HttpResponseMessage response = client.DeleteAsync(mp.ActionName + "/" + textReader.Name).Result;
                                    if (response.StatusCode == HttpStatusCode.OK)
                                    {
                                        var customerJsonString = await response.Content.ReadAsStringAsync();
    
                                        var postData = "The Option  response for Xml   for HttpRequest is " + customerJsonString;
                                        ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "The Option  response for Xml   for HttpRequest is " + customerJsonString);
                                        dicHttpRequest = postData;
    
                                    }
                                    else
                                    {
                                        var customerJsonString = await response.Content.ReadAsStringAsync();
    
                                        var postData = "The Option  response for Xml   for HttpRequest is " + customerJsonString;
                                        ErrorLogger.dologging("XmlManipulator", "GetHttpRequest", "The Option  response for Xml   for HttpRequest is " + customerJsonString);
                                        dicHttpRequest = postData;
    
                                    }
                                    return dicHttpRequest;
    
    
    
                                }
    
    
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in OPTIONS which uses XML.");
                        }
                        try
                        {
                            if (mp.AcceptFormat.ToLower().Trim() == "application/json")
                            {
    
                                if (IsValidJson(mp.InputString))
                                {
    
    
    
    
                                }
                            }
                        }
                        catch (Exception Ex)
                        {
                            ErrorLogger.dologging("XmlManipulator", "HttpResponseAsync", "Error in OPTIONS which uses Json.");
                        }
                        return dicHttpRequest;
                    }
    
                return dicHttpRequest;
    
    
    
            }
            

    Tuesday, November 20, 2018 2:54 AM

All replies

  • User-474980206 posted

    not for any standard webapi. POST, PUT, DELETE, MERGE, OPTIONS, HEAD & GET are verbs not action names.

    also you have lots a redundant/duplicate code. why the duplicate code for http/https?

    POST, PUT, MERGE  can be handled the same, just the verb and payload differs 

    HEAD has no body and just returns the headers, no body

    DELETE has no body and returns just a status

    note: to set the verb in HttpWebRequest, use the Method property.

    Tuesday, November 20, 2018 4:28 PM
  • User-148788041 posted

    Hi,

    This code works for an Api for Delete,post,put,merge. I had tested this.

    Will this same code work for any Api.

    Tuesday, November 20, 2018 4:36 PM
  • User-474980206 posted

    only for a non-standard api like yours, where the REST verbs are route action names. 

    just create a sample webapi project from the template, and your code will not be able to call values controller, which uses the request verb (method) for routing (action names match the request method name)

    Tuesday, November 20, 2018 11:23 PM
  • User-148788041 posted

    i have given following 

    1. End point - Web api url
    2. Method  - Get or post or delete
    3. Method name - 
    Wednesday, November 21, 2018 2:24 AM
  • User-474980206 posted

    yes, but not for OPTIONS, which seems to use DELETE and PUT, PATCH, MERGE seem to have no calls at all.

    again you code should be refactored to simpler and more concise. it looks like just a bunch of pasted together snippets.

    also many api's will require a bearer token and you have no support for this.

    Wednesday, November 21, 2018 4:09 PM
  • User-148788041 posted

    Friends

    I  am using dictionary<String,object>. 

    i return result a object . 

    I need to read values from object for GET,POST,DELETE,PATCH ,OPTIONS AND MERGE

    Wednesday, November 21, 2018 5:15 PM