Можно использовать такой вариант.
Курсы забираются с
www.bank.gov.ua через объект XMLHTTP. На выходе получаем контейнер с курсами валют (данные соответствуют таблице на странице с курсами)
Метод работает как на клиенте, так и на сервере. Настройки для прокси берутся из IE, так что, в случае необходимости, надо будет настроить его для пользователя, под которым запускается AOS
X++:
static server container GetExchRate(TransDate _exchDate = systemDateGet())
{
Com xmlhttp;
InteropPermission InteropPermission;
TextBuffer tb = new TextBuffer();
container rows;
void GetRows(str _class)
{
int pos;
str s;
int pos1;
int len;
int posRowStart;
int posRowEnd;
container row;
TextBuffer tbRow = new TextBuffer();
;
while (tb.find(strfmt(@'\<tr class="%1"', _class), pos))
{
pos1 = tb.matchPos();
len = tb.matchLen();
if (tb.find(@"\<td", pos1))
{
posRowStart = tb.matchPos();
if (tb.find(@"\</tr\>", posRowStart))
{
posRowEnd = tb.matchPos();
s = tb.subStr(posRowStart, posRowEnd - posRowStart);
s = StrReplace(s, '\r\n', "");
s = StrReplace(s, '\t', "");
tbRow.setText(s);
pos1 = 1;
row = connull();
while (tbRow.find(@'\>[^\<]*\</td\>', pos1))
{
s = tbRow.subStr(tbRow.matchPos()+1, tbRow.matchLen()-6);
row += [s];
pos1 = tbRow.matchPos()+tbRow.matchLen();
}
rows += [row];
pos = tb.matchPos() + tb.matchLen();
}
else
pos = pos1+len;
}
else
pos = pos1+len;
}
}
;
InteropPermission = new InteropPermission(InteropKind::ComInterop);
InteropPermission.assert();
xmlhttp = new Com(@"Msxml2.XMLHTTP.3.0");
xmlhttp.open(@"GET", strfmt(@"http://www.bank.gov.ua/Fin_ryn/OF_KURS/Currency/FindByDate.aspx?Text1=%1&__EVENTTARGET=Gr1",
date2str(_exchDate, 123, 2, 2, 2, 2, 4)), false);
xmlhttp.setRequestHeader(@"Accept", @"*/*");
xmlhttp.setRequestHeader(@"Accept-Language", @"ru-RU");
xmlhttp.setRequestHeader(@"User-Agent", @"Axapta");
xmlhttp.setRequestHeader(@"Connection", @"Keep-Alive");
xmlhttp.setRequestHeader(@"Content-Type", @"application/x-www-form-urlencoded");
xmlhttp.setRequestHeader(@"If-Modified-Since", @"Sat, 1 Jan 2000 00:00:00 GMT"); // Для отключения кэша
xmlhttp.send();
if (xmlhttp.status() == 200)
{
tb.setText(xmlhttp.responseText());
GetRows(@"G1");
GetRows(@"w1");
}
CodeAccessPermission::revertAssert();
return rows;
}