【问题标题】:Xamarin Android - Load a WebView using CookieContainer and javascriptXamarin Android - 使用 CookieContainer 和 javascript 加载 WebView
【发布时间】:2013-09-24 21:58:26
【问题描述】:

我正在尝试使用与我的应用程序中的其他 HttpWebRequests 相同的 sessionId 加载 WebView,并且该页面具有需要运行的 javascript。

我正在设置 _webView.JaveScriptEnabled = true;

当我使用 LoadUrl 加载页面时,javascript 会运行,但发送的 ASP.NET_SessionId 与我的其他 HttpWebRequests 发送的会话 ID 不同,并且我无法设置 CookieContainer:

_webView.LoadUrl(apiBase + "/App/Index");

当我使用 HttpWebRequest 检索页面时,我能够设置 CookieContainer 并加载页面,但 javascript 不运行:

var httpReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(apiBase + "/App/Index"));
httpReq.CookieContainer = cookieContainer;
var response = (HttpWebResponse)httpReq.GetResponse();
使用 (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
var viewResult = ;
_webView.LoadData (sr.ReadToEnd(), "text/html", "UTF-8");
}

如何在一次网络通话中同时获得两种行为?

【问题讨论】:

    标签: javascript android webview xamarin


    【解决方案1】:

    我找到了,我需要更改
    _webView.LoadData (sr.ReadToEnd(), "text/html", "UTF-8");

    _webView.LoadDataWithBaseURL (apiBase, sr.ReadToEnd(), "text/html", "UTF-8", "");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-25
      • 2011-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多