Guest User

Untitled

a guest
Dec 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. Declare @TheURL VARCHAR(255) = 'http://ip.jsontest.com/' ,-- the url of the web service
  2. @TheResponse NVARCHAR(4000), --the resulting JSON
  3. @source nvarchar(255), --error source
  4. @description nvarchar(255) --error description
  5. DECLARE @obj INT, @hr INT, @status INT, @message VARCHAR(255);
  6. EXEC @hr = sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT; --not really sure what ProgID or CLSID this is referencing
  7. select @hr
  8. EXEC @hr = sp_OAMethod @obj, 'open', NULL, 'GET', @TheURL, false;
  9. select @hr
  10. IF @hr = 0
  11. EXEC @hr = sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type',
  12. 'application/x-www-form-urlencoded';
  13. select @hr
  14. SET @message = 'sp_OAMethod Send failed';
  15. EXEC @hr = sp_OAMethod @obj, send, NULL, '';
  16. select @hr
  17. exec sp_OAGetErrorInfo @obj, @source out, @description out
  18. select @source, @description
  19. IF @hr = 0 EXEC @hr = sp_OAGetProperty @obj, 'status', @status OUT;
  20. IF @status <> 200 BEGIN
  21. SELECT @message = 'sp_OAMethod http status ' + Str(@status), @hr = -1;
  22. END;
  23. SET @message = 'sp_OAMethod read response failed';
  24. IF @hr = 0
  25. BEGIN
  26. EXEC @hr = sp_OAGetProperty @obj, 'responseText', @Theresponse OUT;
  27. END;
  28. EXEC sp_OADestroy @obj;
  29. IF @hr <> 0 RAISERROR(@message, 16, 1);
Add Comment
Please, Sign In to add comment