0
我正在使用jQuery進行休息。jQuery.ajax在C#中休息後等效#
$.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'
});
這篇文章正確,適用於我需要的東西。我試圖在我的MVC4控制器中使用C#做類似的事情。
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();
}
不幸的是,它總是超時。不知道我做錯了什麼。