HttpWebRequest in 3.5

I have to back port everything to 3.5 and had a hell of a time getting it to work. Here’s what finally succeeded.



            var httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);

            httpWebRequest.Timeout = 50000;            httpWebRequest.Proxy = null;

            httpWebRequest.AllowAutoRedirect = true;

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";

            httpWebRequest.Method = "POST";

            httpWebRequest.Accept = "application/json";

            httpWebRequest.KeepAlive = false;

            //Technically posts should use 100-continue, but I'm lazy

            httpWebRequest.ServicePoint.Expect100Continue = false;




            var postData = "type=potato";




            try

            {

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))

                {

                    streamWriter.Write(postData);// DO NOT TRY TO ENCODE IN ASCII/UTF8

                    streamWriter.Flush();

                    streamWriter.Close();

                }

            }

Comments

Popular posts from this blog

Blocking Bad Light Sources(Sjogren's?)

Hot Spots for Possible B-Cell Disorders(Lupus/Sjogren/Chronic Fatigue)