开发者

Request a page with server code

开发者 https://www.devze.com 2023-02-07 02:41 出处:网络
I need to request a开发者_开发技巧 seriesof pages and want to do from the server codeas if you were doing withAjax, I can do?, thanksYou\'re looking for the WebClient class.Use this c# function. Add u

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


You're looking for the WebClient class.


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消