Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a function to send request and get html web site and Response.Write the html. when the site use ajax code the browser can not load ajax because html and JavaScript code was response.write in my web site page how can call WebMethod function without ajax and JavaScript , in C# code behind?
C#
Tuple<string, System.Net.CookieContainer> tuple = Web_Functions.GetHtmlSourceAndCookies(site ), cookies);
Response.Write(tuple .Item1);

public static Tuple<string, CookieContainer> GetHtmlSourceAndCookies(string Url, CookieContainer cookies)
{
    try
    {
        Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
        HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(Url);
        Request.AllowAutoRedirect = true;
        Request.CookieContainer = cookies;
        Request.UserAgent = "Foo";
        Request.Accept = "*/*";
        using (HttpWebResponse response = (HttpWebResponse)Request.GetResponse())
        {
            Stream ReceiveStream = response.GetResponseStream();
            StreamReader readStream = new StreamReader(ReceiveStream, encode);
            string strWebFramResponse = readStream.ReadToEnd();
            readStream.Close();
            response.Close();
            return Tuple.Create(strWebFramResponse, cookies); 
        }
    }
    catch (WebException ex)
    {
        return Tuple.Create("false", cookies); 
    }
}
Posted
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900