客户端请求服务器的一个页面somepage.aspx?id=0,页面返回一些字符串。我是通过Response.write返回的,但是客户端请求的结果包含html代码,能不能只返回值?另外,这是需要服务器页面需要处理的问题,还是客户端请求时需要处理的问题?

解决方案 »

  1.   

    不知道说清楚没有。服务器通过request.querystring得到参数后,用response.write返回值。客户端请求时,希望只得到值,而不含有html代码。之前的页面都是asp的,不存在这个问题。现在用aspx不知道怎么解决。或者说,是修改客户端的请求方式?
      

  2.   

    楼主可以将 你的字符内容直接给客户端 输出成.txt文本添加引用
    using System.IO;
    using System.Text;string content = 你处理后获得的字符串... MemoryStream ms = new MemoryStream();  
            byte[] bt = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(content);
            ms.Write(bt, 0, bt.Length);
            Response.Clear();
            Response.AddHeader("Content-Type", "text/plain");
            Response.AddHeader("Content-Disposition", "attachment;filename=" + "tests.txt");
            Response.BinaryWrite(bt);
            Response.End();
      

  3.   

    谢谢hertcloud,lovehongyun。
    有没有别的办法,使得客户端能得到返回值,而返回值既不在页面上显示也不另存为文件?
      

  4.   

    客户端请求是通过程序发送httpwebrequest,而不是直接点开这个页面。
      

  5.   


    估计LZ是在js,Xmlhttp返回数据如果是的话,那么
    你直接接收responseText就可以了估计LZ是在alert(responseText)的时候看到一些html代码.
      

  6.   

    另外,我用http/https Protocal Debuger测试,请求这个页面,返回的结果里面并不包含页面返回值,只有html代码。这是为什么
      

  7.   

    tryResponse.Clear();
    Response.Write("I'm a super man!!!");
    Response.End();
      

  8.   

    我用了Response.ContentEncoding=Encoding.GetEncoding("gb2312");为什么用工具测试的结果里中文部分还是乱码?
      

  9.   

    Response.Clear();
            Response.Write(mystr);
            Response.End();