You are querying with Content-Type: application/json
, and so the string in the body is treated as a JSON string. The JSON string must be double and special characters must be escaped using the character \
( specification ).
, "C:\\Users\\futerm\\Downloads\\test"
.
, Content-Type: text/plain
. , .
.
[HttpPost]
public async Task<IActionResult> Post()
{
var directoryPath = await Request.GetRawBodyStringAsync();
if (string.IsNullOrEmpty(directoryPath))
{
return NotFound("DirectoryPath is empty");
}
return Ok(directoryPath);
}
:
public static class HttpRequestExtensions
{
public static async Task<string> GetRawBodyStringAsync(this Microsoft.AspNetCore.Http.HttpRequest request, System.Text.Encoding encoding = null)
{
if (encoding == null)
encoding = System.Text.Encoding.UTF8;
using (var reader = new System.IO.StreamReader(request.Body, encoding))
return await reader.ReadToEndAsync();
}
}
, , , .