์๋ฒ์์ ์ค๋ ์๋ต ๋ฉ์์ง๋ฅผ ๋ณผ ์ ์์ต๋๊น? ๊ทธ๋ ๋ค๋ฉด ์๋ฅผ ๊ฒ์ํ ์ ์์ต๋๊น?
์์ฒญ์ด ์ค๋ฅ๋ฅผ ๋ฐํํ ๋ ๋ณผ ์ ์์ด์ผ ํ๋ฏ๋ก "์ค๋ฅ" ํ ์คํธ๋ฅผ ๋ฐฐ์นํ๋ ์์น์ ์ด ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋ ค๊ณ ํฉ๋๋ค.
๊ฐ์ฌ ํด์!
ํ ๊ฐ์ง ํด๊ฒฐ์ฑ ์ SendAsync ๋ฉ์๋๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํ๋ ๊ฒ์ ๋๋ค.
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = null;
try
{
BeforeSend?.Invoke(this, request);
response = await (SendAsyncMethod.Invoke(Handler, new object[] { request, cancellationToken }) as Task<HttpResponseMessage>);
return response;
}
finally
{
AfterSend?.Invoke(this, response);
}
}
๊ทธ๋ฆฌ๊ณ ์ด๋ฒคํธ ํธ๋ค๋ฌ๋
/// <summary>
/// Occurs before a HTTP request sending.
/// </summary>
public event EventHandler<HttpRequestMessage> BeforeSend;
/// <summary>
/// Occurs after received a response of a HTTP request. (include it wasn't succeeded.)
/// </summary>
public event EventHandler<HttpResponseMessage> AfterSend;
๋๋ ์ด ์ ์์ ๋ฐ์๋ค์๋ค. Sorta๋ ์ฒ์๋ถํฐ ๊ทธ๋์ผ ํ๋ ๊ฒ ๊ฐ์ต๋๋ค. EventArgs e
์ ์ ์ฉ์ฑ์ ์ดํดํ์ง ์๋ ํ ์ด ์ธํฐ์
ํฐ๋ฅผ ํจ์ฌ ๋ ์ ์ฉํ๊ฒ ๋ง๋ญ๋๋ค.
์ข์ ํผ๋๋ฐฑ ๊ฐ์ฌํฉ๋๋ค! ๐
@khamang์ด ์ ์ํ ์๋ก์ด ๊ธฐ๋ฅ์ ํฌํจํ๋ "Blazor WebAssembly(ํด๋ผ์ด์ธํธ ์ธก) HttpClient ์ธํฐ์ ํฐ" v.6.1.0์ ๊ฒ์ํ์ต๋๋ค !
์ฐธ์กฐ: https://github.com/jsakamoto/Toolbelt.Blazor.HttpClientInterceptor/#the -arguments-of-event-handler
๊ทธ๋์ ์ด๊ฒ์ ๊ณ ์ณ์ผ ํฉ๋๊น? AfterSend์์ ์๋ต ์ฝํ
์ธ ์ ์ก์ธ์คํ๋ ค๋ ๊ฒฝ์ฐ ์ฌ์ ํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
http.PostAsync๊ฐ ์ ๊ฒจ ์๊ธฐ ๋๋ฌธ์ ๋ณธ๋ฌธ์ ์ก์ธ์คํ ์ ์๋๋ก ๋ง๋๋ ์๋น์ค์์ ๋งํฉ๋๋ค.
@Swerik ์ ๋ณด ํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
๊ทธ๋์ ์ด๊ฒ์ ๊ณ ์ณ์ผ ํฉ๋๊น? ์ฌ์ ํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค ...
์ด ์ค๋ ๋๋ ์ค๋ฅ ๋ณด๊ณ ์๊ฐ ์๋๋ผ ์๋ก์ด ๊ธฐ๋ฅ ์ ์ ์ค๋ ๋์
๋๋ค.
์ง๊ธ ์ ๊ณ ํ์ ๋ฌธ์ ์ ๋ฌธ์ ๊ฐ ์๋ ์ค์ ๋ชฐ๋์ต๋๋ค.
๋์ค์ ๊ทธ ๋ฌธ์ ๋ฅผ ์ฌํํ๋ ค๊ณ ํ๊ณ ์ฌํํ ์ ์์ผ๋ฉด ์์ ํ๋๋ก ๋ ธ๋ ฅํ๊ฒ ์ต๋๋ค.
์ค ์ด๊ฒ ๋ง๋์ค ์์๋๋ฐ ๋ ์์ธํ ์๋ก์ด ์ด์๋ฅผ ๋ง๋ค๊ฒ
@Swerik ๊ฐ์ฌํฉ๋๋ค!