.net api介面接收字串或者xml

邢帅杰發表於2024-03-08
a
/// <summary>
/// 接收字串或者xml
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<JsonResult> AcceptXMLOrString()
{
    var len = Convert.ToInt32(HttpContext.Request.ContentLength);
    byte[] byt = new byte[len];
    var ri = HttpContext.Request.BodyReader.AsStream().Read(byt, 0, len);
    var str = Encoding.UTF8.GetString(byt, 0, len);
    ApiResult<string> result = new ApiResult<string>()
    {
        errorCode = "0",
        message = "success",
        data = str
    };
    return new JsonResult(result);
}

相關文章