开发者

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜