Create Web Request in C# using asp.net
Name Space
using System.Collections.Specialized;
using System.Net;
using System.IO;
public string Post_Method(string uri, string command)
{
WebRequest req = null;
WebResponse rsp = null;
string tempReply = "";
try
{
req = WebRequest.Create(uri);
req.Method = "post";
req.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.Write(command);
writer.Close();
// Send the data to the webserver
rsp = req.GetResponse();
StreamReader reader = new StreamReader(rsp.GetResponseStream());
tempReply = reader.ReadToEnd().ToString();
tempReply = tempReply.Trim();
}
catch (Exception ex)
{
tempReply = "01";
}
return tempReply;
}
{
WebRequest req = null;
WebResponse rsp = null;
string tempReply = "";
try
{
req = WebRequest.Create(uri);
req.Method = "post";
req.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.Write(command);
writer.Close();
// Send the data to the webserver
rsp = req.GetResponse();
StreamReader reader = new StreamReader(rsp.GetResponseStream());
tempReply = reader.ReadToEnd().ToString();
tempReply = tempReply.Trim();
}
catch (Exception ex)
{
tempReply = "01";
}
return tempReply;
}
Comments
Post a Comment