Monday, 28 January 2013

Pass values from one domain to other domain


Page in Domain 1
protected void Button1_Click(object sender, EventArgs e)
{
    string remoteUrl = "http://localhost:54358/PostDataFromOneWebsiteToAnother/Page2_CS.aspx";
    string firstName = "Raghavendra";
    string lastName = "Aitha";
    ASCIIEncoding encoding = new ASCIIEncoding();
    string data = string.Format("FirstName={0}&LastName={1}", firstName, lastName);
    byte[] bytes = encoding.GetBytes(data);
    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(remoteUrl);
    httpRequest.Method = "POST";
    httpRequest.ContentType = "application/x-www-form-urlencoded";
    httpRequest.ContentLength = bytes.Length;
    using (Stream stream = httpRequest.GetRequestStream())
    {
        stream.Write(bytes, 0, bytes.Length);
        stream.Close();
    }
}

 Page in Domain 2
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.Form.Count > 0)
    {
        string firstName = Request.Form["FirstName"];
        string lastName = Request.Form["LastName"];
    }
}

No comments:

Post a Comment