src/Web/WebMVC/Controllers/TestController.cs
(完整代码) 1KBnamespace WebMVC.Controllers;
class TestPayload
{
public int CatalogItemId { get; set; }
public string BasketId { get; set; }
public int Quantity { get; set; }
}
[Authorize]
public class TestController : Controller
{
private readonly IHttpClientFactory _client;
private readonly IIdentityParser<ApplicationUser> _appUserParser;
public TestController(IHttpClientFactory client, IIdentityParser<ApplicationUser> identityParser)
{
_client = client;
_appUserParser = identityParser;
}
public async Task<IActionResult> Ocelot()
{
var url = "http://apigw/shopping/api/v1/basket/items";
var payload = new TestPayload()
{
CatalogItemId = 1,
Quantity = 1,
BasketId = _appUserParser.Parse(User).Id
};
var content = new StringContent(JsonSerializer.Serialize(payload), System.Text.Encoding.UTF8, "application/json");
var response = await _client.CreateClient(nameof(IBasketService))
.PostAsync(url, content);
if (response.IsSuccessStatusCode)
{
var str = await response.Content.ReadAsStringAsync();
return Ok(str);
}
else
{
return Ok(new { response.StatusCode, response.ReasonPhrase });
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。