byte[] content = Encoding.UTF8.GetBytes(data);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(content,0,content.Length);
response = (HttpWebResponse)request.GetResponse();
reader = new StreamReader(response.GetResponseStream(),System.Text.Encoding.UTF8);
String resultData = reader.ReadToEnd();
I am getting data in response, also on doing Quick Watch of reader.ReadToEnd() it shows data in VS, but resultData always comes empty.
Any Idea what wrong I am doing here?
If you’re using
reader.ReadToEnd()in the debugger, then by the time you try to callReadToEnd()within the actual code, there won’t be any more data.Note that you should use a
usingstatement for the response, so that you close it when you’re done.