我正在使用 jQuery 进行休息。
$.ajax({
url: 'https://graylogurl/gelf',
dataType: 'json',
data: '{"short_message":"test message", "host":"localhost", "facility":"ajax", "_environment":"dev", "_meme":"yolo", "full_message":"this will contain a longer message"}',
type: 'POST'
});
这篇文章正确,可以满足我的需要。我尝试使用 C# 在我的 MVC4 控制器中做类似的事情
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://graylogurl/gelf");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
httpWebRequest.KeepAlive = false;
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"short_message\":\"test message\", \"host\":\"localhost\", \"facility\":\"ajax\", \"_environment\":\"dev\", \"_meme\":\"yolo\", \"full_message\":\"this is from the controller\"}";
streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
不幸的是,它总是超时。不知道我做错了什么。