[英].NET Core 3.1 WebApi - Passthrough JSON response from another WebApi
I have the following setup:我有以下设置:
WebApi #2 needs to call WebApi #1 and simply pass the JSON result back via its OkResult. WebApi #2 需要调用 WebApi #1 并通过其 OkResult 将 JSON 结果传回。 The issue I have is if I do that, I end up with escaped JSON in the response:
我遇到的问题是,如果我这样做,我最终会在响应中逃脱 JSON :
"{\"id\":1,\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\"}"
What is the best way to just passthrough this return?什么是通过此回报的最佳方式?
UPDATE:更新:
Here is the code that makes the API call to WebApi #1:这是使 API 调用 WebApi #1 的代码:
public async Task<string> Get(string uri)
{
try
{
string responseBody = await _client.GetStringAsync(uri);
return responseBody;
}
catch (HttpRequestException ex)
{
_logger.LogError(ex.Message);
return null;
}
}
And here is the return in WebApi #2:这是 WebApi #2 中的返回值:
public async Task<IActionResult> Get(string data)
{
var uri = String.Format(Environment.GetEnvironmentVariable("ENDPOINT"), data);
var result = await _client.Get(uri);
return Ok(result);
}
You need to do this:你需要这样做:
return Content(result, "application/json");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.