Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Declare @TheURL VARCHAR(255) = 'http://ip.jsontest.com/' ,-- the url of the web service
- @TheResponse NVARCHAR(4000), --the resulting JSON
- @source nvarchar(255), --error source
- @description nvarchar(255) --error description
- DECLARE @obj INT, @hr INT, @status INT, @message VARCHAR(255);
- EXEC @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT; --not really sure what ProgID or CLSID this is referencing
- select @hr
- EXEC @hr = sp_OAMethod @obj, 'open', NULL, 'GET', @TheURL, false;
- select @hr
- IF @hr = 0
- EXEC @hr = sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type',
- 'application/x-www-form-urlencoded';
- select @hr
- SET @message = 'sp_OAMethod Send failed';
- EXEC @hr = sp_OAMethod @obj, send, NULL, '';
- select @hr
- exec sp_OAGetErrorInfo @obj, @source out, @description out
- select @source, @description
- IF @hr = 0 EXEC @hr = sp_OAGetProperty @obj, 'status', @status OUT;
- IF @status <> 200 BEGIN
- SELECT @message = 'sp_OAMethod http status ' + Str(@status), @hr = -1;
- END;
- SET @message = 'sp_OAMethod read response failed';
- IF @hr = 0
- BEGIN
- EXEC @hr = sp_OAGetProperty @obj, 'responseText', @Theresponse OUT;
- END;
- EXEC sp_OADestroy @obj;
- IF @hr <> 0 RAISERROR(@message, 16, 1);
Add Comment
Please, Sign In to add comment