Sunday, July 29, 2012

Scrape / download / get a webservice in a textbox or in variable c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;

public partial class Default7 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Your webservice...
        string url = "http://localhost:64907/WebSite2/rss.ashx";
        string strResult = "";

        WebResponse objResponse;
        WebRequest objRequest = System.Net.HttpWebRequest.Create(url);

        objResponse = objRequest.GetResponse();

        using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
        {
            strResult = sr.ReadToEnd();
            // Close and clean up the StreamReader
            sr.Close();
        }

        // Display results to a webpage
        //Response.Write(strResult);
        //webservice in textbox
        TextBox1.Text = strResult.ToString();
    }
}

No comments: