본문 바로가기
C#

[C#] Webview2 API POST 하기

by Jcoder 2021. 7. 27.

2022-04-08

- header에 바로 추가하게 코드 수정.

byte[] byteArray = Encoding.UTF8.GetBytes("보낼 데이터");
// ex) id=abc&pw=123
using (MemoryStream stream = new MemoryStream(byteArray))
{
    var request = webView2.CoreWebView2.Environment.CreateWebResourceRequest(url, "POST", stream, "");
    request.Headers.SetHeader("Content-Type", "application/x-www-form-urlencoded");
    request.Headers.SetHeader("Authorization", {인증할 token});

    webView2.CoreWebView2.NavigateWithWebResourceRequest(request);
    await Task.Delay(100);
}

코드

CoreWebView2Environment.CreateWebResourceRequest(String, String, Stream, String) Method (Microsoft.Web.WebView2.Core) | Microsoft Docs

 

CoreWebView2Environment.CreateWebResourceRequest(String, String, Stream, String) Method (Microsoft.Web.WebView2.Core)

Creates a new CoreWebView2WebResourceRequest object.

docs.microsoft.com

 

'C#' 카테고리의 다른 글

[C#] WinUI3 소개  (0) 2021.08.16
[C#] Get HttpStatusCode Message  (0) 2021.08.02
[C#] Webview2 STATUS_INVALID_IMAGE_HASH 오류 해결  (0) 2021.07.26
[C#] IP 변경  (0) 2021.07.25
[C#] Everything SDK 사용  (0) 2021.07.25