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;
}
}
}
'초짜 IT보이 서바이벌 스토리 > C#' 카테고리의 다른 글
#NuGet #Package in the #Solution #Folder (0) | 2021.05.03 |
---|---|
#튜플 #tuple #c#7 #테스트 #코드 #test #code (0) | 2020.11.03 |
What's New in C# 8.0 (0) | 2019.06.05 |
[MVC] #DropdownList #드롭다운 리스트 만들기 #List<SelectListItem> (0) | 2019.02.23 |
[LInq query] 테이블 컬럼 1개 가져오기 (0) | 2019.02.22 |