Reputation: 581
My requirement is to show a dynamic web page in windows phone app.
The code snippet :
private string MYACCOUNT_URL = "http://www.abc.com"
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
try
{
//Initialization
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(MYACCOUNT_URL);
WebReq.CookieContainer = cookies;
//Our method is post, otherwise the buffer (postvars) would be useless
WebReq.Method = "POST";
//We use form contentType, for the postvars.
WebReq.ContentType = "application/x-www-form-urlencoded";
//WebHeaderCollection headers = new WebHeaderCollection();
//headers[HttpRequestHeader.UserAgent] = useragent;
//WebReq.Headers = headers;
//WebReq.Headers["User-Agent"] = useragent;
//var userAgent = WebReq.GetType().GetProperty("UserAgent");
//if (null != userAgent)
//{
// userAgent.SetValue(WebReq, useragent, null);
//}
//WebReq.UserAgent = userAgent.ToString();
Cookie emailCookie = new Cookie("email", Constants.LoginUserName);
WebReq.CookieContainer.Add(new Uri(MYACCOUNT_URL), emailCookie);
Cookie userIdCookie = new Cookie("id", Constants.UserId);
WebReq.CookieContainer.Add(new Uri(MYACCOUNT_URL), userIdCookie);
Cookie tokenCookie = new Cookie("token", Constants.AccessToken);
WebReq.CookieContainer.Add(new Uri(MYACCOUNT_URL), tokenCookie);
WebReq.BeginGetResponse(new AsyncCallback(MyAccountResponseCallback), WebReq);
}
catch (WebException ex)
{ }
}
private void MyAccountResponseCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
string responseString = streamRead.ReadToEnd();
responseString = Regex.Replace(responseString, "<!DOCTYPE html>", "", RegexOptions.IgnoreCase).Trim();
responseString = Regex.Replace(responseString, "<html lang=\"en\">", "<html>", RegexOptions.IgnoreCase).Trim();
responseString = Regex.Replace(responseString, "<meta charset=\"utf-8\"", "<meta", RegexOptions.IgnoreCase).Trim();
if (response.StatusCode == HttpStatusCode.OK)
{
Dispatcher.BeginInvoke(() =>
{
web_browser.NavigateToString(responseString);
});
}
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse
response.Close();
}
catch (WebException ex)
{
}
}
The web page is loaded properly. Web page contains forms, jquery-ajax. These events(click/load) are getting triggered from the loaded web page. The same web page is getting loaded in Internet Explorer and working fine with all the events on the windows phone 8.
Please suggest any solution. Thanks in advance.
Upvotes: 1
Views: 498
Reputation: 581
Thanks for your response. unfortunately "IsScriptEnabled" is not helpful here. But I got a solution. I am using "Navigate" method instead of "NavigateToString" and it is working. It is loading the web page and also it let me do all events present on web page.
Thanks
Upvotes: 1