Charlie Calvert on Elvenware

Writing Code and Prose on Computers


Web Requests

using System;
using System.IO;
using System.Net;
using System.Text;

namespace Anitya.Utils
    public class RetrieveFromWeb
        /// <summary>
        /// Retrieve a page from the web
        /// </summary>
        /// <param name="webSite">The site you want to query</param>
        /// <param name="getVars">The parameters of the query</param>
        /// <param name="webResponse">Out parameter has response</param>
        /// <returns>Contents of page you asked to retrieve</returns>
        public string GetPageFromWeb(string webSite, string getVars, 
        	out HttpWebResponse webResponse)
            // Call over the network
            string requestString = string.Format(webSite, getVars);
            HttpWebRequest webRequest = 
            webRequest.Method = "GET";
            webResponse = (HttpWebResponse)webRequest.GetResponse();

            // Read and display response
            Stream Answer = webResponse.GetResponseStream();
            StreamReader answer = new StreamReader(Answer);
            return answer.ReadToEnd();