Public String webrequest (method, string URL, string postdata)
{
Httpwebrequest webrequest = NULL;
Streamwriter requestwriter = NULL;
String responsedata = "";
Webrequest = system. net. webrequest. Create (URL) as httpwebrequest;
Webrequest. method = method. tostring ();
Webrequest. servicepoint. expect100continue = false;
// Webrequest. useragent = "Identify your application please .";
// Webrequest. Timeout = 20000;
If (Method = method. Post | Method = method. Put)
{
If (Method = method. Put)
{
Webrequest. contenttype = "text/XML ";
Webrequest. method = "put ";
}
Else
Webrequest. contenttype = "application/X-WWW-form-urlencoded ";
// Webrequest. contenttype = "multipart/form-Data ";
// Post the data.
Requestwriter = new streamwriter (webrequest. getrequeststream ());
Try
{
Requestwriter. Write (postdata );
}
Catch
{
Throw;
}
Finally
{
Requestwriter. Close ();
Requestwriter = NULL;
}
}
Responsedata = webresponseget (webrequest );
Webrequest = NULL;
Return responsedata;
}
Public String webresponseget (httpwebrequest webrequest)
{
Streamreader responsereader = NULL;
String responsedata = "";
Try
{
Responsereader = new streamreader (webrequest. getresponse (). getresponsestream ());
Responsedata = responsereader. readtoend ();
}
Catch
{
Throw;
}
Finally
{
Webrequest. getresponse (). getresponsestream (). Close ();
Responsereader. Close ();
Responsereader = NULL;
}
Return responsedata;
}