1.服务器端。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strPost=string.Empty;
try
{
strPost= Request["postName"];
}
catch
{
}
string strGet=string.Empty;
try
{
strGet = Request.QueryString["getName"].ToString();
}
catch
{
}
StreamWriter swLog= new StreamWriter(Server.MapPath(".") + "//logs.shtml", true, Encoding.UTF8);//所有保存历史数据
FileInfo filelogs = new FileInfo(Server.MapPath(".") + "//logs.shtml");
if (filelogs.Length / (1024 * 1024) > 9)//当文件大于10M时,将文件删除。
{
filelogs.Delete();
}
swLog.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "-------------------------------------------------------");
swLog.WriteLine("Post Value://" + strPost);
swLog.WriteLine("Get Value://" + strGet);
swLog.Close();
StreamWriter swFresh = new StreamWriter(Server.MapPath(".") + "//fresh.shtml", false, Encoding.UTF8);//显示最新数据
swFresh.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "--------------------------------------------");
swFresh.WriteLine("Post Value://" + strPost);
swFresh.WriteLine("Get Value://" + strGet);
swFresh.Close();
}
}
2.客户端(winFrom)
WebClient webclient= new WebClient();
System.Collections.Specialized.NameValueCollection PostDatas = new System.Collections.Specialized.NameValueCollection();
PostDatas.Add(strPost, msg);
webclient.UploadValues("http://defualt.aspx?getName=oookk","POST", PostDatas);
3.小结:
其实保存到log这部分可以稍作修改,可以做为程序的捕获异常的LOG档。