public async Task Should_Validate_Drivers() { Controllers.API.DriversController controller = new Controllers.API.DriversController(); Models.RaidID.DriversRequest request = new Models.RaidID.DriversRequest() { BirthDate = "1985-02-08", GivenName = "Mary", FamilyName = "Lee", LicenceNumber = "94977000", StateOfIssue = "ACT" }; //await controller.Post(request); }
public async Task <IActionResult> Create(Drivers model) { Models.RaidID.DriversRequest request = new Models.RaidID.DriversRequest() { BirthDate = model.BirthDate, FamilyName = model.FamilyName, GivenName = model.GivenName, LicenceNumber = model.LicenceNumber, StateOfIssue = model.StateOfIssue }; var payload = JsonConvert.SerializeObject(request); // Wrap our JSON inside a StringContent which then can be used by the HttpClient class var httpContent = new StringContent(payload, System.Text.Encoding.UTF8, "application/json"); httpContent.Headers.Add("token", api_key); using (var httpClient = new HttpClient()) { // Do the actual request and await the response var httpResponse = await httpClient.PostAsync(api_url + "/dvs/drivers", httpContent); // If the response contains content we want to read it! if (httpResponse.Content != null && httpResponse.StatusCode == System.Net.HttpStatusCode.OK) { var responseContent = await httpResponse.Content.ReadAsStringAsync(); var claim = model.ToClaim(); // IAccount account = new Nethereum.Web3.Accounts.Account(base.GetKey(0), Nethereum.Signer.Chain.Rinkeby); // ClaimsContract contract = new ClaimsContract(node, account); // String tx = await contract.SetClaim(claim.Subject, claim.Key, claim.Value); // ViewBag.Tx = tx; return(View()); } else { return(View("error")); } } }
public async Task Post(Models.RaidID.DriversRequest request) { var payload = JsonConvert.SerializeObject(request); // Wrap our JSON inside a StringContent which then can be used by the HttpClient class var httpContent = new StringContent(payload, Encoding.UTF8, "application/json"); httpContent.Headers.Add("token", api_key); using (var httpClient = new HttpClient()) { // Do the actual request and await the response var httpResponse = await httpClient.PostAsync(url, httpContent); // If the response contains content we want to read it! if (httpResponse.Content != null && httpResponse.StatusCode == System.Net.HttpStatusCode.OK) { var responseContent = await httpResponse.Content.ReadAsStringAsync(); // From here on you could deserialize the ResponseContent back again to a concrete C# type using Json.Net } } }