I am using C #.
The first time I use WebRequest GetRequestStream () in my code, it takes up to 20 seconds. After that, it will take less than 1 second.
Below is my code. The string "this.requestStream = httpRequest.GetRequestStream ()" causes a delay.
StringBuilder postData = new StringBuilder(100); postData.Append("param="); postData.Append("test"); byte[] dataArray = Encoding.UTF8.GetBytes(postData.ToString()); this.httpRequest = (HttpWebRequest)WebRequest.Create("http://myurl.com"); httpRequest.Method = "POST"; httpRequest.ContentType = "application/x-www-form-urlencoded"; httpRequest.ContentLength = dataArray.Length; this.requestStream = httpRequest.GetRequestStream(); using (requestStream) requestStream.Write(dataArray, 0, dataArray.Length); this.webResponse = (HttpWebResponse)httpRequest.GetResponse(); Stream responseStream = webResponse.GetResponseStream(); StreamReader responseReader = new System.IO.StreamReader(responseStream, Encoding.UTF8); String responseString = responseReader.ReadToEnd();
How can I find out what causes this? (ex: DNS lookup? Server not responding?)
Thanks and respect, Koen
c #
koen
source share