본문 바로가기
젬스it

webview2. 요청데이터 캡쳐

by 젬스컬쳐 캐리커처 2024. 9. 6.
반응형

요청 데이터 캡처
이벤트에 무엇이 발사되는지 결정하는 필터를 설정하면 이벤트 자체를 처리하여 개별 들어오는 요청을 캡처하고 요청 데이터를 캡처할 수 있습니다.

Csharp
private void CoreWebView2_WebResourceRequested(object sender, CoreWebView2WebResourceRequestedEventArgs e)
{
    var headers = e.Request.Headers;
    string postData = null;
    var content = e.Request.Content;
    
    // get content from stream
    if (content != null)
    {
        using (var ms = new MemoryStream())
        {
            content.CopyTo(ms);
            ms.Position = 0;
            postData = Encoding.UTF8.GetString(ms.ToArray());
        }
    }
    var url = e.Request.Uri.ToString();

// collect the headers from the collection into a string buffer
    StringBuilder sb = new StringBuilder();
    foreach (var header in headers)
    {
        sb.AppendLine($"{header.Key}: {header.Value}");
    }
    
    // for demo write out captured string vals
    Debug.WriteLine($"{url}\n{sb.ToString()}\n{postData}\n---");
}

반응형

'젬스it' 카테고리의 다른 글

sockJs 역할  (7) 2024.09.12
인그레스서버 역할  (0) 2024.09.11
websocketsharp.closeeventargs code 종류  (0) 2024.09.02
시놀로지 NAS에 아이폰을 백업하고 복원하는 방법  (2) 2024.08.30
닷넷에서 machine key를 변경  (0) 2024.08.26