有很多方法可以从SQL Server触发Web服务,其中一种是sp_OAMethod
方法。
我希望能够使用sp_OAMethod
我发送两个值Group_name_1
和Group_name_2
:
Declare @Object as Int;
Declare @ResponseText as Varchar(8000);
Declare @Body as varchar(8000) =
'{
"group_name_1":"Group3","group_name_2":"Group3"
}'
Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;
EXEC sp_OAMethod @Object, 'open', NULL, 'post','https://localhost:44336/api/values/', 'false'
Exec sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Type', 'application/json'
Exec sp_OAMethod @Object, 'send', null, @body
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
Select @ResponseText
Exec sp_OADestroy @Object
运行代码时,此查询始终返回NULL,并且未发出POST请求。
有帮助吗?