sp_OACreate 'Microsoft.XMLHTTP' 'GET' запрос через HTTPS

elBrujo
Дата: 14.02.2013 19:11:10
Взял пример запроса, который получает xml ответ через http запрос. С http никаких проблем нет, но встал вопрос получить данные через https. При выполнении возникает ошибка "0x800C0019 msxml3.dll Неправильный сертификат безопасности, необходимый для доступа к этому ресурсу." Попробовал обратиться к этой теме (http://www.sql.ru/forum/actualthread.aspx?tid=885864&hl=sp_oacreate), но ничего не получилось, та же ошибка. Может кто сталкивался с таким вопросом?

declare @retcode int, @local int, @status int, @url varchar (255)

set @url = 'https://195.248...'


EXEC @retcode = sp_OACreate 'Microsoft.XMLHTTP', @local OUT
IF @retcode<>0
EXEC sp_OAGetErrorInfo @local

EXEC @retcode = sp_OAMethod @local, 'Open', NULL, 'GET', @url, 'False'
IF @retcode<>0
EXEC sp_OAGetErrorInfo @local

EXEC @retcode = sp_OAMethod @local, 'SEND', NULL, @status
IF @retcode<>0
EXEC sp_OAGetErrorInfo @local

EXEC @retcode = sp_OAGetProperty @local, 'status', @status OUT
IF @retcode<>0
EXEC sp_OAGetErrorInfo @local

IF @status <> 200
RAISERROR('Invalid response status',16,1)

IF object_id('tempdb..#httpresult') is not null drop table #httpresult
create table #httpresult(http ntext)

insert #httpresult
EXEC @retcode = sp_OAGetProperty @local, 'responsetext'
IF @retcode<>0
EXEC sp_OAGetErrorInfo @local

SELECT http, datalength(http) from #httpresult

EXEC @retcode = sp_OADestroy @local


IF object_id('tempdb..#httpresult') is not null drop table #httpresult
ziktuw
Дата: 14.02.2013 20:36:43
А если через IE к этому ресурсу обратиться, не вылазит предупреждение безопасности?
Сергей Мишин
Дата: 15.02.2013 00:36:43
elBrujo
Попробовал обратиться к этой теме (http://www.sql.ru/forum/actualthread.aspx?tid=885864&hl=sp_oacreate), но ничего не получилось, та же ошибка.

В этой ветке есть рабочий пример, но с MSXML2.ServerXMLHTTP
declare @obj int, @ret  int, @text varchar(max), @url varchar(max)

select @url = 'https://94.100.191.244'

exec @ret = sp_OACreate 'MSXML2.ServerXMLHTTP', @obj out
IF @ret <> 0 exec sp_OAGetErrorInfo @obj

exec @ret = sp_OAMethod @obj, 'Open', null, 'GET', @url, 'false'
if @ret <> 0 exec sp_OAGetErrorInfo @obj

exec @ret = sp_OAMethod @obj, 'setRequestHeader', null, 'Content-Type', 'text/xml; charset=utf-8'
if @ret <> 0 exec sp_OAGetErrorInfo @obj

exec @ret = sp_OAMethod @obj, 'setOption', null, 2 ,13056  -- игнорировать сертификат
if @ret <> 0 exec sp_OAGetErrorInfo @obj

EXEC @ret = sp_OAMethod @obj, 'SEND'
if @ret <> 0 exec sp_OAGetErrorInfo @obj

EXEC @ret = sp_OAGetProperty @obj, 'responsetext'
if @ret <> 0 exec sp_OAGetErrorInfo @obj
....

Через Microsoft.XMLHTTP вроде нельзя, но могу и ошибаться.
elBrujo
Дата: 15.02.2013 11:38:37
Сергей Мишин, большое спасибо.
Помогло.
Значит таки https надо делать через,
MSXML2.ServerXMLHTTP
а не через
Microsoft.XMLHTTP
.