C#标准响应数据
public HttpResponseMessage UpdateModule(Mode mode)
{
var response = Process.Instance.ExecuteString(() =>
{ var count = DbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parms); if (count < )
{
resultMsg.ResultMsg = "更新失败";
return resultMsg.ToJson();
} resultMsg.Result = ;
resultMsg.total = ;
resultMsg.ResultMsg = "更新成功"; return resultMsg.ToJson(); }); return HttpHelper.ResponseMessagetoJson(response);
}
public class Process
{
private static volatile Process _process = null;
private readonly string returnMsg = "{\"RowsCount\":0,\"Result\":-1,\"ResultMsg\":\" api 500 error\",\"Rows\":null}"; protected Process()
{ } /// <summary> Gets the instance
/// </summary>
public static Process Instance
{
get
{
if (_process == null)
{
lock (typeof(Process))
{
if (_process == null)
{
_process = new Process();
}
}
}
return _process;
}
} public string ExecuteString(Func<string> action)
{
try
{
return action.Invoke();
}
catch (Exception ex)
{
Logger.Error(ex);
return returnMsg;
}
} public dynamic ExecuteStringExtend(Func<dynamic> action)
{
try
{
return action.Invoke();
}
catch (Exception ex)
{
Logger.Error(ex);
return returnMsg;
}
} public string ExecuteStringtran(Func<string> action,ITransactionManager tran)
{
try
{
return action.Invoke();
}
catch (Exception ex)
{
Logger.Error(ex);
if (tran != null) tran.Rollback();
return returnMsg;
}
}
}
public static class HttpHelper
{
public static HttpResponseMessage ResponseMessagetoJsonExtnd(string str)
{
var response = new HttpResponseMessage(HttpStatusCode.OK);
HttpContent content = response.Content;
response.Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "text/html");
return response;
} public static HttpResponseMessage ResponseMessagetoJson(object obj)
{
string str;
if ((obj is string) || (obj is char))
{
str = obj.ToString();
}
else
{
str = obj.ToJson();
}
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "text/html")
};
return response;
}
public static HttpResponseMessage ResponseMessagetoJsonExtend(string str)
{
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "text/html")
};
return response;
}
}
C#标准响应数据的更多相关文章
- jQuery-1.9.1源码分析系列(十六)ajax——响应数据处理和api整理
ajax在得到请求响应后主要会做两个处理:获取响应数据和使用类型转化器转化数据 a.获取响应数据 获取响应数据是调用ajaxHandleResponses函数来处理. ajaxHandleRespon ...
- rest-assured之验证响应数据(Verifying Response Data)
前面的文章中已经介绍过了如果获得响应数据,接下来我们来介绍一下应该如何来验证这些获得的响应数据,比如验证状态码.状态行.cookies.header.content-type以及body体. 1.验证 ...
- 使用HttpServletRequestWrapper修改请求参数 和 使用HttpServletResponseWrapper截获响应数据
Servlet规范中的Filter引入了一个功能强大的拦截模式.Filter能在request到达servlet的服务方法之前拦截request对象,而在服务方法转移控制后又能拦截response对象 ...
- Jmeter运行后,查看结果树中的响应数据出现中文乱码。
参考:https://blog.csdn.net/qq_15228737/article/details/82597482 https://baike.baidu.com/item/UTF-8/481 ...
- Java框架之SpringMVC 03-RequestMapping-请求数据-响应数据
SpringMVC SpringMVC是一种轻量级的.基于MVC的Web层应用框架. 通过一套 MVC 注解,让 POJO 成为处理请求的控制器,而无须实现任何接口. 采用了松散耦合可插拔组件结构,比 ...
- 用 jQuery.ajaxSetup 实现对请求和响应数据的过滤
不知道同学们在做项目的过程中有没有相同的经历呢?在使用 ajax 的时候,需要对请求参数和响应数据进行过滤处理,比如你们觉得就让请求参数和响应信息就这么赤裸裸的在互联网里来回的穿梭,比如这样: 要知道 ...
- ASP.NET Core 中文文档 第四章 MVC(2.3)格式化响应数据
原文:Formatting Response Data 作者:Steve Smith 翻译:刘怡(AlexLEWIS) 校对:许登洋(Seay) ASP.NET Core MVC 内建支持对相应数据( ...
- Jmeter—5 关联 响应数据传递-正则表达式提取器
在测试过程中,遇到一个问题:用户登录成功后服务器会返回一个登录凭证,之后所有的操作都需要带上此凭证.我们怎么获取登录凭证并传递给后续的操作? Jmeter提供了正则表达式提取器,用变量提取参数,后续通 ...
- Jmeter—4 添加断言 判断响应数据是否符合预期
发出请求之后,通过添加断言可以判断响应数据是否是我们的预期结果. 1 在Jmeter中发送一个登录的http请求(参数故意输入错误).结果肯定是登陆失败啦. 但结果树中http请求的图标显示‘绿色’表 ...
随机推荐
- DataTableToJson
public static string CreateJsonParameters(DataTable dt,string JsonName) { StringBuilder JsonString = ...
- URAL 1915 Titan Ruins: Reconstruction of Bygones(思路)
搞这个题差不多是从比赛开始到结束. 从自信慢慢的看题一直到wrong到死. 这个题目可以说成是思路题,以为我们只要明白一点,这道题就成了纯暴力的水题, 那就是当操作数不足栈中数字数目的时候,我们就没有 ...
- Javac不是内部或外部指令
JDK安装完,命令行窗口中运行Java正常,运行Javac显示不是内部或外部指令 不存在百度上说的没有安装JDK,只安装了JRE 我的电脑是64位Win7操作系统 第一次安装的JDK不是从官网下载的, ...
- 禁用 WebView 放大镜及拷贝粘贴弹出框
文/KyXu(简书作者)原文链接:http://www.jianshu.com/p/40048d9c979a著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 背景:当你的App中有 We ...
- entlib验证组件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- WCF的一点补充-Restful相关
参考 配置WCF心得 对REST架构 风格下WCF的一点补充 Securing WCF REST Service with Azure AppFabric Access Control Service ...
- C#设计模式(17)——观察者模式(Observer Pattern)
一.引言 在现实生活中,处处可见观察者模式,例如,微信中的订阅号,订阅博客和QQ微博中关注好友,这些都属于观察者模式的应用.在这一章将分享我对观察者模式的理解,废话不多说了,直接进入今天的主题. 二. ...
- pasteimg浏览器中粘贴图片jQuery插件
pasteimg是一款可以在浏览器中实现图片粘贴的jQuery插件,兼容Chrome.Firefox.IE11以及其他使用这些内核的浏览器,比如,国内著名的360浏览器. pasteimg可以识别浏览 ...
- Nodejs学习笔记(十一)--- 数据采集器示例(request和cheerio)
目录 写在之前 示例 示例要求 采集器 加入代理 请求https 写在之后... 写在之前 很多人都有做数据采集的需求,用不同的语言,不同的方式都能实现,我以前也用C#写过,主要还是发送各类请求和正则 ...
- js命名规范