Windows runtime WinRT 8.1 WebView内容类型

Windows runtime WinRT 8.1 WebView内容类型,windows-runtime,Windows Runtime,我正在尝试使用Windows Phone 8.1中的HttpRequestMessage加载Web视图。问题是,在签入Fiddler时,内容标题中缺少内容类型标题 byte[] postData = GetWebviewPostDataBytes(); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, prepareUri(url));

我正在尝试使用Windows Phone 8.1中的HttpRequestMessage加载Web视图。问题是,在签入Fiddler时,内容标题中缺少内容类型标题

            byte[] postData = GetWebviewPostDataBytes();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, prepareUri(url));
            var httpContent = new HttpBufferContent(postData.AsBuffer());
            httpContent.Headers.Add("Content-Type", GetContentType());
            request.Headers.Add("User-Agent", GetUserAgent());
            request.Content = httpContent;
            webView.NavigateWithHttpRequestMessage(request);

我发现了一些链接,其中这是一个内部错误。有人能告诉我一个解决方法吗

我找到的唯一解决方案是使用表单加载页面

我正在加载一个本地HTML页面,该页面由我的POST参数生成。这个页面包含一个隐藏的HTML表单,我将在页面加载后提交该表单

然后,网页加载为:

  • 在隐藏的输入字段中生成带有表单和参数的本地HTML页面
  • 在Web视图中加载此页面
  • 加载页面后,使用webpage postContent()函数请求提交表单
  • 然后,webview将导航到设置了内容类型标题的预期网页
  • 这个示例代码在WinJS中,但它可以很容易地在C#中转换,因为它是相同的webview组件

    var htmlContent     = "<html><head><script type='text/javascript'>function postContent(){document.getElementById('postForm').submit();}</script></head><body><form id='postForm' action='{targetUrl}' method='post'>{inputFields}</form></body></html>";
    var inputFields     = "";
    var iterator        = payloadContent.first();
    while(iterator.hasCurrent)
    {
        inputFields     += "<input hidden='on' name='{n}' value='{v}'/>".replace("{n}", iterator.current.key).replace("{v}", iterator.current.value);
        iterator.moveNext();
    }
    var htmlContent     = htmlContent.replace("{targetUrl}", "YOUR URL HERE").replace("{inputFields}", inputFields);
    this._webviewElement.navigateToString(htmlContent);
    

    希望这有帮助。

    谢谢!对我的解决方案使用了类似的方法。
    this._webviewElement.invokeScriptAsync("postContent");