HttpWebRequest and HttpWebResponse - here are the two classes to simulate the web browser funtionality in smart client applications.
We can use the following method when we had to call a web page which return the result as Xml.
public static string GetHttpRequest(StringBuilder data, string sourcePath)
{
Stream aStream = null;
try
{
//Send POST request web page
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourcePath);
req.Method = "POST";
// Content type is xml
req.ContentType = "text/xml";
req.Credentials = CredentialCache.DefaultCredentials;
if (data.Length > 0)
{
req.ContentLength = data.Length;
StreamWriter sw = new StreamWriter(req.GetRequestStream());
sw.Write(data.ToString());
sw.Flush();
sw.Close();
}
// Create The Response Object And Fill It By Sending The Request;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
aStream = response.GetResponseStream();
StreamReader sr = new StreamReader(aStream);
StringBuilder sbOutput = new StringBuilder();
char[] buffer = new char[1024];
int r;
while ((r = sr.Read(buffer, 0, buffer.Length)) > 0)
sbOutput.Append(buffer, 0, r);
return sbOutput.ToString();
}
catch (WebException ex)
{
//TODO: handle exception
}
catch (Exception ex)
{
//TODO: handle exception
}
finally
{
aStream.Close();
}
return string.Empty;
}
Showing posts with label Data One. Show all posts
Showing posts with label Data One. Show all posts
Monday, March 5, 2007
Sunday, March 4, 2007
web automation - Fetch / Send HTTP Post data to a Web Server
Since last two days i am googling for how to fetch and post data on websites using the standard .net aplication.
Such applications will be helpful in many scenarios . Examples of application using the above technique
1) Website Testing
2) Website Downloader
3) Stress testing of Server and Websites
4) Data pulling from websites - like fetching usage data from BSNL Data One server -:)
Such applications will be helpful in many scenarios . Examples of application using the above technique
1) Website Testing
2) Website Downloader
3) Stress testing of Server and Websites
4) Data pulling from websites - like fetching usage data from BSNL Data One server -:)
Subscribe to:
Posts (Atom)
