I have a RestSharp Entitlement check code that works, but I need to replace it with one that uses native C# library (Net.Http). So I was wondering what will the equivalent of my code be using native C#.
Here is my code:
public static bool Entitlement(string appId, string userId)
{
//REST API call for the entitlement API.
//We are using RestSharp for simplicity.
//You may choose to use another library.
//(1) Build request
var client = new RestClient();
client.BaseUrl = new System.Uri(@"https://apps.example.com/");
//Set resource/end point
var request = new RestRequest();
request.Resource = "webservices/checkentitlement";
request.Method = Method.GET;
//Add parameters
request.AddParameter("userid", userId);
request.AddParameter("appid", appId);
//(2) Execute request and get response
IRestResponse response = client.Execute(request);
//Get the entitlement status.
bool isValid = false;
if (response.StatusCode == HttpStatusCode.OK)
{
JsonDeserializer deserial = new JsonDeserializer();
EntitlementResponse entitlementResponse = deserial.Deserialize<EntitlementResponse>(response);
isValid = entitlementResponse.IsValid;
}
//
return isValid;
}
class EntitlementResponse
{
public string UserId { get; set; }
public string AppId { get; set; }
public bool IsValid { get; set; }
public string Message { get; set; }
}
try this