HttpRequest request = HttpContext.Current.Request;
HttpResponse response = HttpContext.Current.Response;
request.ContentType = "json";
response.ContentType = "json";
StreamReader reader = new StreamReader(request.InputStream);
string test = reader.ReadToEnd();
//写入文本
const string fileName = "2.json";
string filepath = Server.MapPath("." + "\\" + fileName);
try
{
if (File.Exists(filepath))
{
string delFile = filepath;
File.Delete(delFile);
}
using (StreamWriter sw = File.CreateText(filepath))
{
sw.Write(test);
sw.Close();
}
}
catch (Exception)
{
response.Write("{\"result\":\"sorry\"}");
return;
}
response.Write("{\"result\":\"ok\"}");
}
HttpResponse response = HttpContext.Current.Response;
request.ContentType = "json";
response.ContentType = "json";
StreamReader reader = new StreamReader(request.InputStream);
string test = reader.ReadToEnd();
//写入文本
const string fileName = "2.json";
string filepath = Server.MapPath("." + "\\" + fileName);
try
{
if (File.Exists(filepath))
{
string delFile = filepath;
File.Delete(delFile);
}
using (StreamWriter sw = File.CreateText(filepath))
{
sw.Write(test);
sw.Close();
}
}
catch (Exception)
{
response.Write("{\"result\":\"sorry\"}");
return;
}
response.Write("{\"result\":\"ok\"}");
}