返回> 网站首页 

WebServices输出自定义字符串、输出不创建文件

yoours2013-11-26 17:08:50 阅读 1482

简介一边听听音乐,一边写写文章。

在使用.net编写Web Services调用结果会输出xml格式文本,而不是自定义的纯字符串文本,例如json。

一、使WebServices支持post、get两种请求方式
修改Web.config配置文件中system.web节,增加如下:
<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>

二、输出自定义字符串
Context.Response.Write("1");
        Context.Response.End();

三、输出不创建文件
输出文本文件,但是不要在服务器端创建文件实体。
            Context.Response.Clear();
            Context.Response.Buffer = false;
            Context.Response.ContentType = "application/octet-stream";
            Context.Response.AppendHeader("content-disposition", "attachment;filename=MyFile.txt;");
    Context.Response.Write("文件内容");
            Context.Response.Flush();
            Context.Response.End();

四、输出utf8格式字符串
            Context.Response.Clear();
            Context.Response.Buffer = false;
            Context.Response.ContentType = "text/html;charset=UTF-8";
            Context.Response.Write("utf8格式文本");
            Context.Response.End();

微信小程序扫码登陆

文章评论

1482人参与,0条评论