Way to get content from Webpage

  • Thread starter Thread starter KC Eric
  • Start date Start date
K

KC Eric

Hi all,

Assume that my PPC has wifi ready and is connect to the internet. How
can I get the content of a webpage?

Thanks!

KC Eric
 
public static string SendPost(string serverUrl, string postData, bool Https,
int InetTimeout)
{
try {
HttpWebRequest req;
if (Https)
{
req = (HttpWebRequest)WebRequest.Create("https://" + serverUrl);
req.AllowWriteStreamBuffering = true;
}
else
{
req = (HttpWebRequest)WebRequest.Create("http://" + serverUrl);
req.AllowWriteStreamBuffering = false;
}
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Timeout = InetTimeout * 1000;
req.SendChunked = true;

ASCIIEncoding encodedData = new ASCIIEncoding();
byte[] btPostData;
btPostData = encodedData.GetBytes(postData);

// If the AllowWriteStreamBuffering property of HttpWebRequest is
set to false, the contentlength has to be set to length of data to be posted
else Exception(411) is raised.
if (!Https)
req.ContentLength = btPostData.Length;

Stream reqStream = req.GetRequestStream();

reqStream.Write(btPostData, 0, btPostData.Length);
reqStream.Close();

// Submit the request and get the response object
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();

// Retrieve the response stream and wrap in a StreamReader
Stream respStream = resp.GetResponseStream();
StreamReader rdr = new StreamReader(respStream);

string strResp = rdr.ReadToEnd();
rdr.Close();
respStream.Close();

return strResp;

} catch(WebException we) {
//Util.ErrorAlert("Error sending network post: " + we.Message +
"\nResponse: " + we.Status.ToString());
} catch(Exception e) {
//Util.ErrorAlert("Error sending network post: ", e);
}
return "";
}
 
Back
Top