.NET无法从请求中读取数据

时间:2015-04-16 09:45:11

标签: c# asp.net .net http

我在C#.NET中遇到最简单的请求处理,每当我尝试从请求中读取内容时,我通常会得到一个空值。

代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class server_save : System.Web.UI.Page
{
    private string TXT_PATH = HttpContext.Current.Server.MapPath("files/saved.txt");
    protected void Page_Load(object sender, EventArgs e)
    {

        Response.AppendHeader("Access-Control-Allow-Origin", "*");
        string DATA = Request["data"];
        try
        {
            StreamWriter writer = new StreamWriter(TXT_PATH, true, Encoding.Default);
            writer.WriteLine(DATA);
            writer.Close();
            Response.Write(DATA);
        }
        catch (Exception)
        {
            Response.Write(TXT_PATH);
        }

    }
}

http://pastebin.com/nJYBm4mX

0 个答案:

没有答案