var baseAddress = "https://insights-collector.newrelic.com/v1/accounts/111111/events";
var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));
http.Accept = "application/json";
http.ContentType = "application/json";
http.Method = "POST";
http.Headers.Add("X-Insert-Key", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
ASCIIEncoding encoding = new ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(jsondata);
**Stream newStream = http.GetRequestStream();**
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();
var response = http.GetResponse();
var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
content = sr.ReadToEnd().ToString();
当我在本地机器上执行上述代码时,我得到了来自 newrelic 网站的响应,但是当我将相同的代码移动到 Windows Server 2012 时,编译器不会在这一行之后
Stream newStream = http.GetRequestStream();
而且它也没有抛出任何异常。