Search This Blog

Sunday, September 9, 2012

How can I copy something from a webpage to my webpage ?

Fetching data from another website to our web site.


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


namespace SBIWEB
{
    public partial class callwebpage : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            StreamWriter sms_writer = null;

            string str_request = "x=" + "y";

            Uri url = new Uri("http://webdigitalseo.com/");
            if (url.Scheme == Uri.UriSchemeHttp)
            {     //Create Request Object
                HttpWebRequest objRequest = (HttpWebRequest)HttpWebRequest.Create(url);
               // HttpWebRequest objRequest = (HttpWebRequest)HttpWebRequest.Create(url + str_request);
                //Set Request Method  
                //objRequest.Method = WebRequestMethods.Http.Post;
                objRequest.Method = "post";
                objRequest.ContentLength = str_request.Length;
                objRequest.ContentType = "application/x-www-form-urlencoded";
                sms_writer = new StreamWriter(objRequest.GetRequestStream());
                sms_writer.Write(str_request);
                sms_writer.Close();

                //Get response from requested url  
                HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                //Read response in stream reader  
                StreamReader reader = new StreamReader(objResponse.GetResponseStream());
                string tmp = reader.ReadToEnd();
                objResponse.Close();     //Set response data to container  
                Response.Write(tmp);
            }
        }
    }
}

No comments :