protected void Page_Load(object sender, EventArgs e)
    {
        string str = Request.Form["loc"];
        Response.Write(str);
    }这个代码没有问题啊,能取到post的数据。

解决方案 »

  1.   

    不过,你的客户端要想接收到你返回的hello,还需要做些修改:
     protected void Page_Load(object sender, EventArgs e)
            {
                string str = Request.Form["loc"];            Response.Clear();
                Response.ContentType = "text/plain";
                Response.Write(str);
                Response.End();
            }
      

  2.   

    winform中确实可以获取到数据,但是我想在网页上获得winform post的值后进行一些操作,不过貌似都操作不了
      

  3.   


    <%@ WebHandler Language="C#" Class="CardDelete" %>using System;
    using System.Web;public class CardDelete : IHttpHandler
    {    public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);        string cardNo = context.Request["cardNo"];         context.Response.Write("成功");
        }    public bool IsReusable
        {
            get
            {
                return false;
            }
        }} public static string PostData(string ashx, string data)
            {
                try
                {
                    var client = new WebClient();
                    client.Encoding = Encoding.UTF8;
                    var url = ashx;
                    if (data!="")
                    {
                        url +="?"+data;
                    }
                    var result = client.UploadString(url,data);
                    return result;
                }
                catch (Exception ex)
                {
                    return "";
                }
            }  var res =PostData("http://xxxxxx.com/GetCard.ashx", "id=5");
      if(res=="成功")
    {
    }
      

  4.   

    第一段表示接口
    第二段封装了post 方法.
    第三段表示调用方法并且接收返回值..
    如果这你还是看不懂我也没办法了...
      

  5.   


    你没说你要操作什么啊。我其实想做的操作是 网页获取 post的值,然后写入文件或者写入数据库这种操作,不过我现在加上protected void Page_Load(object sender, EventArgs e)
        {
            string A = Request.Form["a"];//由winform中传给网页的参数用a标识 ­
            string B = Request.Form["b"];
            //int C = Convert.ToInt32(A) + Convert.ToInt32(B);
            string C = B;
            C += A;        if (C == "")
            {
                C = "Hello world!";
                Response.Write(C);//将数据写到网页中
            }
            else
            {
                FileStream fs = new FileStream("D:\\A.txt", FileMode.Append); 
                StreamWriter sw = new StreamWriter(fs, Encoding.Default); 
                sw.Write(C); 
                sw.Close(); 
                fs.Close();
                Response.Write(C);//将数据写到网页中
                Response.Write(A);//将数据写到网页中
                g_str = C;
            }
        }加入这些操作,在winform端的post的返回就会失败。请帮忙看下。
      

  6.   

    这个是post端获取返回信息哇,
       string cardNo = context.Request["cardNo"];         context.Response.Write("成功");
    我想在这里就加入文件写入操作,            FileStream fs = new FileStream("D:\\A.txt", FileMode.Append); 
                StreamWriter sw = new StreamWriter(fs, Encoding.Default); 
                sw.Write(C); 
                sw.Close(); 
                fs.Close();不过加上这段代码,post 就失败了
      

  7.   

    设置个断点跟踪一下aspx方,估计是写文件出错了。没有权限啥的