The following code fails with a 400 bad request exception. My network connection is good and I can go to the site but I cannot get this uri with HttpWebRequest.
private void button3_Click(object sender, EventArgs e) { WebRequest req = HttpWebRequest.Create(@'http://www.youtube.com/'); try { //returns a 400 bad request... Any ideas??? WebResponse response = req.GetResponse(); } catch (WebException ex) { Log(ex.Message); } }
First, cast the WebRequest to an HttpWebRequest like this:
Then, add this line of code: