> 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 myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
string getDetails = "Argument=SomeTestArguments";
ASCIIEncoding sendEncoding = new ASCIIEncoding();
byte[] byte1 = sendEncoding.GetBytes(getDetails);
myHttpWebRequest.Method = "POST";
// Set the content type of the data being posted.
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
// Set the content length of the string being posted.
myHttpWebRequest.ContentLength = getDetails.Length;
Stream sendStream = myHttpWebRequest.GetRequestStream();
sendStream.Write(byte1,0,byte1.Length);
sendStream.Close();
// info
Console.WriteLine("The value of 'ContentLength' property after sending
the data is {0}", myHttpWebRequest.ContentLength);
// Dump the response
WebResponse myWebResponse = myHttpWebRequest.GetResponse();
Stream ReceiveStream = myWebResponse.GetResponseStream();
Encoding readEncoding = System.Text.Encoding.GetEncoding("utf-8");
// Pipe the stream to a higher level stream reader with the required
encoding format.
StreamReader readStream = new StreamReader(ReceiveStream, readEncoding);
Console.WriteLine("\nResponse stream received");
Char[] read = new Char[256];
// Read 256 charcters at a time.
int count = readStream.Read( read, 0, 256 );
Console.WriteLine("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(str);
count = readStream.Read(read, 0, 256);
}
Console.WriteLine("");
// Release the resources of stream object.
readStream.Close();
// Release the resources of response object.
myWebResponse.Close();
}
}