How to intercept WebResourceRequested to override : Accept-Language RRS feed

  • Question

  • I am working with one of the service, which sends a HTTP Request Message with accept-language param to a web view control.

    I am using inside UWP app.

    I want to the webview to return a customised locale when queried by any http request. I tried overriding response as below : 

    WebView.WebResourceRequested += InterceptWebRequest;

            void InterceptWebRequest(WebView sender, WebViewWebResourceRequestedEventArgs args)
                HttpRequestMessage requestMessage = new HttpRequestMessage();
                requestMessage = args.Request;

                HttpResponseMessage response = new HttpResponseMessage();
                response.RequestMessage = requestMessage;

                args.Response = response;

    But after that nothing is happening , like the webview is not opening the desired URL.

    I tried below code to open the URL 

     var requestMsg = new HttpRequestMessage(HttpMethod.Post, new System.Uri("MyWebService"));
     requestMsg.Headers.Add("accept-header", "it-IT");

    Default behavior of MyWebService is it hits back webview and do the query got "Accept-Header" param. And I want to return a customized value.

    I tried a lot , but unable to solve the issue after overriding WebResourceRequested.

    Can you help me with some fix , using which either I can set the default locale for webview without changing machine's locale, or override the response inside event WebResourceRequested to make the code work.

    • Edited by TusharGuptaMCA Thursday, April 9, 2020 1:41 AM
    • Moved by CoolDadTx Thursday, April 9, 2020 1:40 PM UWA related
    Thursday, April 9, 2020 1:39 AM

All replies

  • Hi TusharGuptaMCA,

    Thank you for posting here.

    Since this thread is related to uwp, so I suggest that you can ask this question in  Microsoft Q&A, they know uwp better.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 9, 2020 3:22 AM