.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

GET / POST

Posted By: Elvis     Posted Date: October 31, 2009    Points:2   Category :C#
Hello.

Can you, please, help me with minimum code required to send Get and Post requests?

Thanks.

Responses
Author: Amit Mehra             
Posted Date: November 01, 2009     Points: 5   

Hi Elvis,

You can modify the Form Tag in your .aspx page in you asp.net application for Post method

eg

<form method="post" action="MyPage.aspx" runat="server">
</form>


Hope i understood your question correctly

Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Elvis             
Posted Date: November 01, 2009     Points: 5   

Hi.

thanks for your replay.
Can I use C# instead of asp.net?
I need to send request, to specific IP and Port, once in "Get" and once in "Post"

Thank you.

Author: Amit Mehra             
Posted Date: November 01, 2009     Points: 5   

Hi Elvis,

Yes you can send request programatically using C#.

Try like this

string url = "http://www.Mywebsite.com";
HttpWebRequest httpWebReq = (HttpWebRequest)WebRequest.Create(url);
string proxy = null;

string data = String.Format("parameter1={0}&parameter2={1}&parameter3={2}", parameter1, parameter2, parameter3);
byte[] buffer = Encoding.UTF8.GetBytes(data);

httpWebReq .Method = "POST"; //You can specify which type do you want
httpWebReq .ContentType = "application/x-www-form-urlencoded";
httpWebReq .ContentLength = buffer.Length;
httpWebReq .Proxy = new WebProxy(proxy, true);
httpWebReq .CookieContainer = new CookieContainer();

Stream reqst = httpWebReq .GetRequestStream();
reqst.Write(buffer, 0, buffer.Length);
reqst.Flush();
reqst.Close();

HttpWebResponse res = (HttpWebResponse)httpWebReq .GetResponse();

Stream resst = httpWebReq .GetResponseStream();
StreamReader sr = new StreamReader(resst);
string response = sr.ReadToEnd();


Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Elvis             
Posted Date: November 01, 2009     Points: 5   

Where do I specify IP / Port?

Author: Amit Mehra             
Posted Date: November 01, 2009     Points: 5   

Hi Elvis,

You can specify the port number in URL itself.

for eg

string url = "http://www.Mywebsite.com:445";

Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend