SQL Server CLR系列(3)-发送POST请求
来源:互联网 发布:系统仿真软件 编辑:程序博客网 时间:2024/06/08 18:27
1.新建一个HTTP请求的自定义函数,C#代码如下:
using System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;using System.Net;using System.Text;using System.IO;public partial class UserDefinedFunctions{ /// <summary> /// 发送Http请求 /// </summary> /// <param name="url">请求地址</param> /// <param name="json">请求参数json格式</param> /// <param name="method">POST/GET</param> /// <returns></returns> [Microsoft.SqlServer.Server.SqlFunction] public static SqlString HttpRequest(SqlString url, SqlString json, SqlString method) { string result = ""; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url.Value); req.Method = method.Value; req.ContentType = "application/x-www-form-urlencoded"; #region 添加Post 参数 byte[] data = Encoding.UTF8.GetBytes(json.Value); req.ContentLength = data.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(data, 0, data.Length); reqStream.Close(); } #endregion HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); //获取响应内容 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { result = reader.ReadToEnd(); } return new SqlString(result); }};
2.Test.sql中测试请求
SELECT dbo.HttpRequest( 'http://localhost:8080/trtapi-web/trtsdms/inStock/orderBlock', 'json={"erp_bilno":"+201709110001+","erp_refno":"","erp_vend":"2","erp_line":"2","erp_batch":"20170531","erp_works":"XP2","erp_store":"010 ","erp_matno":"C41-4-3","erp_quant":"2.33","erp_statu":"A","erp_qty":"0","erp_tkdat":"2017-05-31T14:49:34.740","erp_vddat":"2020-05-01T00:00:00","erp_units":"","erp_flag":"I","erp_makdat":"2017-05-31T00:00:00","erp_mark":"0","erp_mtype":"161","erp_check":"admin9","erp_receive":"哈哈哈","erp_chkdat":"2017-06-05T00:00:00"}', 'POST' );
注意要把项目的安全性改成无限制
阅读全文
0 0
- SQL Server CLR系列(3)-发送POST请求
- SQL Server CLR系列(2)-创建触发器与手动部署
- SQL SERVER CLR UrlDecode
- SQL Server CLR系列(1)-创建CLR项目与自动部署
- SQL Server 访问发送Http请求
- SQL Server 访问发送Http请求
- SQL Server 访问发送Http请求
- Sql server 2005触发器发送http请求
- Jsoup系列学习(1)-发送get或post请求
- IWebBrowser2 发送post请求
- WebClient发送POST请求
- android发送post请求
- Httpclient发送POST请求
- .NET发送POST请求
- IWebBrowser2 发送post请求
- httpClient发送post请求
- python发送post请求
- Android发送post请求
- colorPrimary、colorPrimaryDark、colorAccent
- 运行LINE
- 这里没有key
- PS-day9-个人学习笔记
- BMP格式知识之二:16位,24位,32位的BMP图片算法是如何运算的
- SQL Server CLR系列(3)-发送POST请求
- Hadoop发展简介
- 简单的SpringMVC搭建
- 【机器学习实战】第5章 Logistic回归
- easy ui动态添加菜单
- ubuntu 安装和卸载mysql
- Git Commit failed
- 匿名内部类特点及注意
- java String.split()函数的用法分析