T
TusharGuptaMCA
Guest
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;
requestMessage.Headers.Remove("Accept-Language");
requestMessage.Headers.Add("Accept-Language","ja-JP");
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");
WebView.NavigateWithHttpRequestMessage(requestMsg);
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.
Continue reading...
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;
requestMessage.Headers.Remove("Accept-Language");
requestMessage.Headers.Add("Accept-Language","ja-JP");
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");
WebView.NavigateWithHttpRequestMessage(requestMsg);
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.
Continue reading...