Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Developer,
I have String message and URL.

strmsg = "ABCDEFDYYGYGGY"
Response.Redirect("http://www.teprocess.co.in/Gateway/Request.jsp?msg="+strMsg);

I Send string message with query string and the hit the above URL with String message strmsg .


But i want to Send this String parameter strmsg with the POST Method.
Anybody tell me hows to hit string parameter to URL with POST method in .cs code in c#.

Regards,
Ravi Sharma
Posted

string query = "Hello World";

WebRequest myRequest = WebRequest.Create("https://myurl");
myRequest.Timeout = 60000;
myRequest.Method = "POST";
myRequest.ContentLength = query.Length;
myRequest.ContentType = "application/x-www-form-urlencoded";

StreamWriter postWriter = new StreamWriter(myRequest.GetRequestStream());
postWriter.Write(query);
postWriter.Close();


If you want to get a response back then:
WebResponse myResponse = myRequest.GetResponse();
StreamReader rdr = new StreamReader(myResponse.GetResponseStream());
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Jul-11 13:11pm    
Good answer, only -- where is the string to send with its key. Please explain it. I voted 5, but in advance.
--SA
This example[^] sends parameters using the POST method.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Jul-11 13:09pm    
Why you advice a third-party class; at least add a link to its original source.
--SA
You can use session,hidden field or a protected variable
 
Share this answer
 
Comments
Ravi Sharma 2 12-Jul-11 7:07am    
That i khow how, to use session,hidden field.
Syed Salman Raza Zaidi 12-Jul-11 7:26am    
strmsg = "ABCDEFDYYGYGGY";

Session["abc"] =strmsg;

from the page u want to access, use Session["abc"].toString();

Rate the solution if u like it :)

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