public async Task <BodyModel> EditBody(InputBody editedBody) { string editedBodyJson = JsonSerializer.Serialize(editedBody); HttpContent bodyContent = new StringContent(editedBodyJson, Encoding.UTF8, "application/json"); using HttpResponseMessage response = await HttpClient.PatchAsync("api/bodies", bodyContent); response.EnsureSuccessStatusCode(); string content = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <BodyModel>(content, new JsonSerializerOptions { PropertyNameCaseInsensitive = true })); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] InputBody input, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request. SleepTime : {0}", input.SleepTime); var MessageToSend = new MessageEvent() { DateMessage = DateTime.Now, SleepTime = input.SleepTime }; // Broadcasting the body received to the Event Hub await _EvtHubBroadCaster.SerializeAndBroadCastMessageAsync(MessageToSend); return(new OkObjectResult("Message Sent")); }
public string GetPostSample() { StringBuilder bodyBuilder = new StringBuilder(); using (JsonWriter writer = new JsonTextWriter(new StringWriter(bodyBuilder))) { writer.Formatting = Formatting.Indented; if (InputBody != null) { InputBody.WriteJsonBody(writer); } else { writer.WriteNull(); } writer.Flush(); } return(bodyBuilder.ToString()); }
public async Task beBad() { var projectDir = AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppContext.BaseDirectory.IndexOf("bin")); var configPath = Path.Combine(projectDir, "appsettings.json"); var builder = new ConfigurationBuilder().AddJsonFile(configPath, optional: false); var _configuration = builder.Build(); var model = new InputBody() { Channel = "", Method = "", Path = "" }; var controller = new AccountController(_configuration); var result = await controller.BuildToken(model); var okResult = result; okResult.Should().Be((int)HttpStatusCode.InternalServerError); }
public async Task <IActionResult> BuildToken([FromBody] InputBody models) { var Claims = new[] { new Claim("Input-Body", JsonConvert.SerializeObject(models)), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; var expiration = DateTime.UtcNow.AddDays(1); var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["llave_secreta"])); JwtSecurityToken token = new JwtSecurityToken( claims: Claims, expires: expiration ); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), expiration = expiration })); }
public HttpResponseMessage SomeInputMethod([FromBody] InputBody inputBody) { var x = inputBody.headerData; return(new HttpResponseMessage(System.Net.HttpStatusCode.Accepted)); }