- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
/// <summary>
/// Retrieve currency rates from an external site to be sure they are up to date.
/// In this case just checking the one currency (Australian Dollar) so no need to dynamically parse the site.
/// </summary>
/// <returns>currency rates or msg indicating an error</returns>
private String getCurrencyRates()
{
string strURL = @"http://www.x-rates.com/d/JPY/table.html";
HttpWebRequest txtRequest = (HttpWebRequest)WebRequest.Create(strURL);
txtRequest.Method = "GET";
txtRequest.ContentType = "application/x-www-form-urlencoded";
string response;
using (StreamReader streamReader = new StreamReader(txtRequest.GetResponse().GetResponseStream()))
{
response = streamReader.ReadToEnd();
if (response.IndexOf("Australian Dollar") > 0)
{
//parse the returned page for the two values of the currency rate based on the existing design
int ind_jpy = (response.IndexOf("/d/AUD/JPY/graph120.html") + 39);
int ind_aud = (response.IndexOf("/d/JPY/AUD/graph120.html") + 39);
String jpy_aud = response.Substring(ind_jpy, (response.IndexOf("</a>",ind_jpy) - ind_jpy) );
String aud_jpy = response.Substring(ind_aud, (response.IndexOf("</a>", ind_aud) - ind_aud));
Session["curr_rate"] = "set";
Session["JPY"] = jpy_aud;
Session["AUD"] = aud_jpy;
return aud_jpy + " / " + jpy_aud;
}
//else present msg to user that unable to obtain currency rates
}
return "";
}
guest 07.09.2009 11:41 # 0
striker 07.09.2009 13:00 # 0
/me пошел размещать вакансии
Ordos 07.09.2009 13:57 # 0
guest 07.09.2009 14:16 # 0
Это неявная ссылка на предыдущий говнокод.
Тема та же: парсинг вместо сервиса
guest 08.09.2009 12:36 # 0
Lemming 25.08.2021 05:37 # 0