Cypher
Cypher

Reputation: 1

Request a page with server code

I need to request a series of pages and want to do from the server code as if you were doing with Ajax, I can do?, thanks

Upvotes: 0

Views: 71

Answers (2)

fkucukbaltaci
fkucukbaltaci

Reputation: 91

Use this c# function. Add using System.Net; top of your page.

private string MakeWebRequest(string url) {
    string retValue = String.Empty;
    try
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse response = null;
        request.Method = "GET";

        response = (HttpWebResponse)request.GetResponse();
        StreamReader stReader = new StreamReader(response.GetResponseStream());

        retValue = stReader.ReadToEnd();

        stReader.Close();
        response.Close();

        stReader.Dispose();
        stReader = null;
        response = null;
        request = null;
    }
    catch (Exception ex) { 

    }


    return retValue;
}

Upvotes: 0

SLaks
SLaks

Reputation: 888167

You're looking for the WebClient class.

Upvotes: 2

Related Questions