using RestSharp;
    using RestSharp.Authenticators;

    namespace User.Model
    {
        
        public class RestCalling
        {
            public string uri { get; set; }
            public string username { get; set; }
            public string password { get; set; }
            public string endPoint { get; set; } //"users/" + userId + "/identities.json"
            public string methodType { get; set; } //PUT, GET, POST, DELETE.

            //GET & Put & Post & Delete
            public string RestClientComm()
            {
                var _client = new RestClient(uri);
                IRestResponse result = null;
                _client.Authenticator = new HttpBasicAuthenticator(username: username, password: password);
                var request = new RestRequest(resource: endPoint, DataFormat.Json);


                switch (methodType)
                {
                    case "PUT": 
                        request.AddParameter("application/json", "\"identity\": {\"value\": \"" + "email@emailAddress" + "\"}}", ParameterType.RequestBody);
                        result = _client.Put(request);
                        break;

                    case "DELETE": 
                        result = _client.Delete(request);
                        break;

                    case "POST": 
                        request.AddParameter("application/json", "{\"identity\": {\"type\": \"email\", \"value\": \"" + "email@emailAddress"+ "\"}", ParameterType.RequestBody);
                        result = _client.Post(request);
                        break;

                    default: //GET
                        result = _client.Get(request);
                        break;

                }

                return result.Content;

            }
        }
    }

Posted by Sungyoup Han matrim

댓글을 달아 주세요

Posted by Sungyoup Han matrim

댓글을 달아 주세요


[참조]; https://msdn.microsoft.com/en-us/library/ms178473.aspx?f=255&MSPPError=-2147217396


ASP.NET 의 라이프 사이클 관련 MSDN 설명입니다. 위 내용에 들어가 있는 ASP.NET 의 Life Cycle 그림입니다. 





Posted by Sungyoup Han matrim

댓글을 달아 주세요