> I was wondering if someone might be able to provide some guidance on
how I could make an http request from a C# library.
static void Main(string[] args)
{
HttpWebRequest myHttpWebReques t = (HttpWebRequest )WebRequest.Cre ate(url);
string getDetails = "Argument=SomeT estArguments";
ASCIIEncoding sendEncoding = new ASCIIEncoding() ;
byte[] byte1 = sendEncoding.Ge tBytes(getDetai ls);
myHttpWebReques t.Method = "POST";
// Set the content type of the data being posted.
myHttpWebReques t.ContentType = "applicatio n/x-www-form-urlencoded";
// Set the content length of the string being posted.
myHttpWebReques t.ContentLength = getDetails.Leng th;
Stream sendStream = myHttpWebReques t.GetRequestStr eam();
sendStream.Writ e(byte1,0,byte1 .Length);
sendStream.Clos e();
// info
Console.WriteLi ne("The value of 'ContentLength' property after sending
the data is {0}", myHttpWebReques t.ContentLength );
// Dump the response
WebResponse myWebResponse = myHttpWebReques t.GetResponse() ;
Stream ReceiveStream = myWebResponse.G etResponseStrea m();
Encoding readEncoding = System.Text.Enc oding.GetEncodi ng("utf-8");
// Pipe the stream to a higher level stream reader with the required
encoding format.
StreamReader readStream = new StreamReader(Re ceiveStream, readEncoding);
Console.WriteLi ne("\nResponse stream received");
Char[] read = new Char[256];
// Read 256 charcters at a time.
int count = readStream.Read ( read, 0, 256 );
Console.WriteLi ne("HTML...\r\n ");
while (count > 0)
{
// Dump the 256 characters on a string and display the string
onto the console.
String str = new String(read, 0, count);
Console.Write(s tr);
count = readStream.Read (read, 0, 256);
}
Console.WriteLi ne("");
// Release the resources of stream object.
readStream.Clos e();
// Release the resources of response object.
myWebResponse.C lose();
}
}