tags:

views:

60

answers:

2

I need to accomplish the following and need help with #2 below

  1. My site has a page with form and the submitted form data needs to be written to a database on my site.
  2. After it is written to the database, the same data submitted on the form needs to be sent to a page that processes it on another site so as if the form submission came from a page on that other site. The page that processes it on the other site is a php page.
+1  A: 

The ideal solution to your problem is that you create a web service on the php site and your asp.net code calls the web service. http://en.wikipedia.org/wiki/Web%5Fservice

Creating a web service in PHP: http://www.xml.com/pub/a/ws/2004/03/24/phpws.html

Calling a web service in ASP.Net: http://www.codeproject.com/KB/webservices/WebServiceConsumer.aspx

Alternatively you could create a http request from your asp.net to the php site posting all the form elements to the php site.

Here is an example: http://www.netomatix.com/httppostdata.aspx

NB: You are almost guaranteed to run into problems with the second approach in the medium to long term, I don't recommend it unless you don't have control over the php site.

Stephen lacy
+1  A: 

It's a bit unclear, but my guess is that you're trying to do a 'form post' to the other .php page after your data is written to the database.

You can more information from this wonderful Scott Hanselman article, but here is the summary:

public static string HttpPost(string URI, string Parameters) 
{
   System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
   req.Proxy = new System.Net.WebProxy(ProxyString, true);
   //Add these, as we're doing a POST
   req.ContentType = "application/x-www-form-urlencoded";
   req.Method = "POST";
   //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value&
   byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
   req.ContentLength = bytes.Length;
   System.IO.Stream os = req.GetRequestStream ();
   os.Write (bytes, 0, bytes.Length); //Push it out there
   os.Close ();
   System.Net.WebResponse resp = req.GetResponse();
   if (resp== null) return null;
   System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
   return sr.ReadToEnd().Trim();
}
Dan Esparza