SqlServer 常用语句方法
HttpClient的帮助类
- public class HttpHelper
- {
- /// <summary>
- /// 发起POST同步请求
- /// </summary>
- /// <param name="url"></param>
- /// <param name="postData"></param>
- /// <param name="contentType">application/xml、application/json、application/text、application/x-www-form-urlencoded</param>
- /// <param name="headers">填充消息头</param>
- /// <returns></returns>
- public static string HttpPost(string url, string postData = null, string contentType = "application/json", int timeOut = 30, Dictionary<string, string> headers = null)
- {
- postData = postData ?? "";
- using (HttpClient client = new HttpClient())
- {
- if (headers != null)
- {
- foreach (var header in headers)
- client.DefaultRequestHeaders.Add(header.Key, header.Value);
- }
- using (HttpContent httpContent = new StringContent(postData, Encoding.UTF8))
- {
- if (contentType != null)
- httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
- HttpResponseMessage response = client.PostAsync(url, httpContent).Result;
- return response.Content.ReadAsStringAsync().Result;
- }
- }
- }
- /// <summary>
- /// 发起POST异步请求
- /// </summary>
- /// <param name="url"></param>
- /// <param name="postData"></param>
- /// <param name="contentType">application/xml、application/json、application/text、application/x-www-form-urlencoded</param>
- /// <param name="headers">填充消息头</param>
- /// <returns></returns>
- public static async Task<string> HttpPostAsync(string url, string postData = null, string contentType = "application/json", int timeOut = 30, Dictionary<string, string> headers = null)
- {
- postData = postData ?? "";
- using (HttpClient client = new HttpClient())
- {
- client.Timeout = new TimeSpan(0, 0, timeOut);
- if (headers != null)
- {
- foreach (var header in headers)
- client.DefaultRequestHeaders.Add(header.Key, header.Value);
- }
- using (HttpContent httpContent = new StringContent(postData, Encoding.UTF8))
- {
- if (contentType != null)
- httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
- HttpResponseMessage response = await client.PostAsync(url, httpContent);
- return await response.Content.ReadAsStringAsync();
- }
- }
- }
- /// <summary>
- /// 发起GET同步请求
- /// </summary>
- /// <param name="url"></param>
- /// <param name="headers"></param>
- /// <param name="contentType"></param>
- /// <returns></returns>
- public static string HttpGet(string url, string contentType = "application/json", Dictionary<string, string> headers = null)
- {
- using (HttpClient client = new HttpClient())
- {
- if (contentType != null)
- client.DefaultRequestHeaders.Add("ContentType", contentType);
- if (headers != null)
- {
- foreach (var header in headers)
- client.DefaultRequestHeaders.Add(header.Key, header.Value);
- }
- HttpResponseMessage response = client.GetAsync(url).Result;
- return response.Content.ReadAsStringAsync().Result;
- }
- }
- /// <summary>
- /// 发起GET异步请求
- /// </summary>
- /// <param name="url"></param>
- /// <param name="headers"></param>
- /// <param name="contentType"></param>
- /// <returns></returns>
- public static async Task<string> HttpGetAsync(string url, string contentType = "application/json", Dictionary<string, string> headers = null)
- {
- using (HttpClient client = new HttpClient())
- {
- if (contentType != null)
- client.DefaultRequestHeaders.Add("ContentType", contentType);
- if (headers != null)
- {
- foreach (var header in headers)
- client.DefaultRequestHeaders.Add(header.Key, header.Value);
- }
- HttpResponseMessage response = await client.GetAsync(url);
- return await response.Content.ReadAsStringAsync();
- }
- }
- /// <summary>
- /// 发起POST同步请求
- /// </summary>
- /// <param name="url"></param>
- /// <param name="postData"></param>
- /// <param name="contentType">application/xml、application/json、application/text、application/x-www-form-urlencoded</param>
- /// <param name="headers">填充消息头</param>
- /// <returns></returns>
- public static T HttpPost<T>(string url, string postData = null, string contentType = "application/json", int timeOut = 30, Dictionary<string, string> headers = null)
- {
- return HttpPost(url, postData, contentType, timeOut, headers).ToEntity<T>();
- }
- /// <summary>
- /// 发起POST异步请求
- /// </summary>
- /// <param name="url"></param>
- /// <param name="postData"></param>
- /// <param name="contentType">application/xml、application/json、application/text、application/x-www-form-urlencoded</param>
- /// <param name="headers">填充消息头</param>
- /// <returns></returns>
- public static async Task<T> HttpPostAsync<T>(string url, string postData = null, string contentType = "application/json", int timeOut = 30, Dictionary<string, string> headers = null)
- {
- var res = await HttpPostAsync(url, postData, contentType, timeOut, headers);
- return res.ToEntity<T>();
- }
- /// <summary>
- /// 发起GET同步请求
- /// </summary>
- /// <param name="url"></param>
- /// <param name="headers"></param>
- /// <param name="contentType"></param>
- /// <returns></returns>
- public static T HttpGet<T>(string url, string contentType = "application/json", Dictionary<string, string> headers = null)
- {
- return HttpGet(url, contentType, headers).ToEntity<T>();
- }
- /// <summary>
- /// 发起GET异步请求
- /// </summary>
- /// <param name="url"></param>
- /// <param name="headers"></param>
- /// <param name="contentType"></param>
- /// <returns></returns>
- public static async Task<T> HttpGetAsync<T>(string url, string contentType = "application/json", Dictionary<string, string> headers = null)
- {
- var res = await HttpGetAsync(url, contentType, headers);
- return res.ToEntity<T>();
- }
- }
- /// <summary>
- /// Json扩展方法
- /// </summary>
- public static class JsonExtends
- {
- public static T ToEntity<T>(this string val)
- {
- return JsonConvert.DeserializeObject<T>(val);
- }
- public static string ToJson<T>(this T entity, Formatting formatting = Formatting.None)
- {
- return JsonConvert.SerializeObject(entity, formatting);
- }
- }
SqlServer 常用语句方法的更多相关文章
- SqlServer常用语句整理
先记录下来 以后整理 1.常用语句 1.1update连表更新 update a set a.YCaseNo = a.WordName + '['+ convert(varchar,a.CaseYea ...
- SqlServer常用语句
首先,写这个的原因是我其实sql语句不太行,总觉得自己写得很乱,好像也没有系统学习过,借此复习和与大家探讨 No.1 关于查询时间区间是否重叠的sql语句 问题是这样:插入之前,想查询同User是否其 ...
- SqlServer常用语句参考
1.SQL SERVER中如何使用SQL 语句复制表结构: select * into 新表 from 旧表 where 1=2 把“旧表”的表结构复制到“新表”,1=2不复制数据,如果要复制数据,就 ...
- C#学习笔记(4)——sqlserver常用语句
说明(2017-5-26 17:29:05): 需要天天练习: 新建表:create table [表名]([自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,[字段1] ...
- sqlserver 常用语句
1.查询表中的RID RID=RowID=(fileID:pageID:slotID) SELECT sys.fn_PhysLocFormatter(%%physloc%%) AS rid,* FRO ...
- MySQL 常用语句大全
MySQL 常用语句大全 一.连接 MySQL 格式: mysql -h 主机地址 -u 用户名 -p 用户密码 1.例 1:连接到本机上的 MYSQL. 首先在打开 DOS 窗口,然后进入目录 my ...
- SQLServer查询语句收集
常用的SQLServer查询语句,有空可以多练习一下,增加记忆,可以提高工作效率! 1.数据操作 Select --从数据库表中检索数据行和列Insert --向数据库表添加新数据 ...
- SQLServer查询语句收集(非常实用)
============================= SQLServer语句收集1 =========================== 1.数据操作 Select --从 ...
- SQL server 常用语句
SQL Server中常用的SQL语句 1.概述 2.查询概述 3.单表查询 4.连接查询 5.带有exists的相关子查询 6.SQL的集合操作 7.插入操作 8.删除操作 9.修改操作 10. ...
随机推荐
- C语言中typedef用法
C语言中typedef用法 1. 基本解释 typedef为C语言的关键字,作用是为一种数据类型定义一个新名字.这里的数据类型包括内部数据类型(int,char等)和自定义的数据类型(struct等) ...
- 尝试在阿里云的Linux服务器器上安装拥有图形界面的Pycharm
在Linux服务器上跑Python项目发现每次从本地上传文件太过麻烦,于是打算在服务器上安装Pycharm直接写Pycharm代码. 去Pycharm的官网下载Linux版本(支持正版于是我下载了 ...
- ubuntu+mysql+php+apache2+wordpress建站全记录
虽然操作并不难,但用到的各种命令,各种坑的解决方法还需要记一下 建好的博客: 念诗之人的博客 VPS和域名选购 VPS选购 国内外有很多商家可供选择,国内有如阿里云,百度云,腾讯云等(ECS,BCC等 ...
- Bayesian Non-Exhaustive Classification A case study:online name disambiguation using temporal record streams
一 摘要: name entity disambiguation:将对应多个人的记录进行分组,使得每个组的记录对应一个人. 现有的方法多为批处理方式,需要将所有的记录输入给算法. 现实环境需要1:以o ...
- HDU_4570_区间dp
http://acm.hdu.edu.cn/showproblem.php?pid=4570 连题目都看不懂,直接找了题解,copy了过来= =. 一个长度为n的数列,将其分成若干段(每一段的长度要& ...
- yum 升级php版本
centos默认安装的php都是 5.3的 ,现在需要 5.6以上的版本 手动安装比较麻烦,直接用yum升级了. 一.准备工作 首先检查当前php版本 #php -v 查看安装的php扩展包 #yu ...
- linux web站点常用压力测试工具httperf
一.工具下载&&安装 软件获取 ftp://ftp.hpl.hp.com/pub/httperf/ 这里使用的是如下的版本 ftp://ftp.hpl.hp.com/pub/httpe ...
- iptables服务器主机防火墙
iptables参数说明: Commands: Either long or short options are allowed. --append -A chain 链尾部追加一条规则 --dele ...
- webpack性能优化
Webpack优化打包速度以及性能优化 1.跟上技术的迭代(Node.Npm.Yarn) 2.在尽可能少的模块上应用loader 3.Plugin尽可能精简并确保可靠 4.resolve参数合理配置 ...
- vue路由--动态路由
前面介绍的路由都是路径和组件一对一映射的 有时候需要多个路径映射到一个组件,这个组件根据参数的不同动态改变,这时候需要用到动态路由 动态路由这样定义路由路径: path: '/foo/:id'--可以 ...