数据库开发
网络新概念,云计算、大数据、O2O、电商。。。。
网络新概念,云计算、大数据、O2O、电商。。。。
2018-08-02 08:41:06
sql发送http的Post请求调用,json数据
SELECT dbo.FN_ZXCC_HTTP_POST('http://172.16.1.1/index.php?c=wx&a=sendQueueMsg&datatype=json','{"fmarkid":"fb2border001","mobile":"1359800xxxx","url":"http://weixin.qq.com/","ftype":"5","first":"中午","keyword1":"keyword1","keyword2":"keyword2","keyword3":"keyword3","remark":"remark"}','application/json','application/json');
存储过程post
-- HTTP POST 请求 -- [测试] -- DROP FUNCTION FN_HTTP_POST; ALTER FUNCTION [dbo].[FN_ZXCC_HTTP_POST]( @URL VARCHAR(256), @DATA VARCHAR(2000), @REQ_H_ACCEPT VARCHAR(256), @REQ_H_CONTENT_TYPE VARCHAR(256) ) RETURNS VARCHAR(5000) AS BEGIN DECLARE @object int, @returnStatus int, @returnText varchar(5000), @errMsg varchar(2000), @httpStatus varchar(20) ; /* 初始化 */ EXEC @returnStatus = SP_OACreate 'Msxml2.ServerXMLHTTP.3.0',@object OUT; IF @returnStatus <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errMsg OUT, @returnText OUT; RETURN ('初始化对象失败,' + @errMsg + ISNULL(@returnText,'')); END /*创建链接*/ EXEC @returnStatus= SP_OAMethod @object,'open',NULL,'post',@URL,'false'; IF @returnStatus <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errMsg OUT, @returnText OUT; RETURN ('创建连接失败,' + @errMsg + ISNULL(@returnText, '')); END EXEC @returnStatus=SP_OAMethod @object,'setRequestHeader',NULL,'Accept',@REQ_H_ACCEPT; EXEC @returnStatus=SP_OAMethod @object,'setRequestHeader',NULL,'Content-Type',@REQ_H_CONTENT_TYPE; EXEC @returnStatus=SP_OAMethod @object,'setRequestHeader',NULL,'Content-Length','1000000'; /*发起请求*/ EXEC @returnStatus= SP_OAMethod @object,'send',NULL,@DATA; IF @returnStatus <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errMsg OUT, @returnText OUT; RETURN ('发起请求失败,' + @errMsg + ISNULL(@returnText, '')); END /*获取HTTP状态代码*/ EXEC @returnStatus = SP_OAGetProperty @Object, 'Status', @httpStatus OUT; IF @returnStatus <> 0 BEGIN EXEC sp_OAGetErrorInfo @Object, @errMsg OUT, @returnText OUT; RETURN ('获取HTTP状态代码失败,' + @errMsg + ISNULL(@returnText, '')); END IF @httpStatus <> 200 BEGIN RETURN ('访问错误,HTTP状态代码:' + @httpStatus); END /*获取返回信息*/ EXEC @returnStatus= SP_OAGetProperty @object,'responseText',@returnText OUT; IF @returnStatus <> 0 BEGIN EXEC SP_OAGetErrorInfo @object, @errMsg OUT, @returnText OUT; RETURN ('获取返回信息失败,' + @errMsg + ISNULL(@returnText, '')); END RETURN @returnText; END;