Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi
i will send data from page A to page B using post method in asp.net


how can it?


C#
//Create a request using a URL that can receive a post. 
WebRequest request = WebRequest.Create("http://forum.example.ir");

 //Set the Method property of the request to POST.
 request.Method = "POST";

//Create POST data and convert it to a byte array.
 string postData = "username=user&passsword=pass&email=behnamhagi@gmail.com";
 byte[] byteArray = Encoding.UTF8.GetBytes(postData);

//Set the ContentType property of the WebRequest.
 request.ContentType = "application/x-www-form-urlencoded";
 
//Set the ContentLength property of the WebRequest.
 request.ContentLength = byteArray.Length;
 
//Get the request stream.
 Stream dataStream = request.GetRequestStream();

//Write the data to the request stream.
 dataStream.Write(byteArray, 0, byteArray.Length);

//Close the Stream object.
 dataStream.Close();

//Get the response.
 WebResponse response = request.GetResponse();

//Display the status.
 Console.WriteLine(((HttpWebResponse)response).StatusDescription);

//Get the stream containing content returned by the server.
 dataStream = response.GetResponseStream();

//Open the stream using a StreamReader for easy access.
 StreamReader reader = new StreamReader(dataStream);

//Read the content.
 string responseFromServer = reader.ReadToEnd();

//Display the content.
 Console.WriteLine(responseFromServer);

//Clean up the streams.
 reader.Close();
 dataStream.Close();
 response.Close();         
Posted
Updated 17-Apr-14 10:10am
v3
Comments
Richard C Bishop 17-Apr-14 15:51pm    
What has the internet told you when you looked it up?
[no name] 17-Apr-14 15:53pm    
find code but Know confusing
Richard C Bishop 17-Apr-14 15:55pm    
That's ok. You take the info you find and start playing with it. After you at least attempt it, you can bring a structured question here with the code in question and we can help you then.
[no name] 17-Apr-14 15:57pm    
please help me on this code
i will send user informatiion to my subdomain
Richard C Bishop 17-Apr-14 16:10pm    
The code literally tells you what each line is doing.

 
Share this answer
 
Comments
[no name] 17-Apr-14 16:19pm    
tnx but its not my means
i will post value from may register page of my web site(asp.net) to my furom(vbulttin)
You can use the HttpWebRequest class and you'll need to know the names of the controls that will be posted. You can easily get that with Fiddler if you need to.

See link for example, http://stackoverflow.com/questions/8538810/how-to-post-data-to-a-website[^]
 
Share this answer
 
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();
   }


Regards,
Praveen Nelge
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900