How to use our ASP.Net Currency Converter
Converting currencies using our ASP.net Exchange Rate API is as easy as posting a HTTP request. Your requests would need to follow
this simple pattern:
Here are some examples in ASP.net:
1. Simple Currency Conversion (in ASP.NET):
To convert currencies from 12.50 USD (US Dollar) to GBP (British Pound):
Dim url As String
url = "www.exchangerate-api.com/usd/gbp/12.50?k=API_KEY"
Dim inStream As StreamReader
Dim webRequest As WebRequest
Dim webresponse As WebResponse
webRequest = webRequest.Create(url)
webresponse = webRequest.GetResponse()
inStream = New StreamReader(webresponse.GetResponseStream())
answer = inStream.ReadToEnd()
Or to get how many Japanese Yen (JPY) there are to the South African Rand (ZAR):
Dim url As String
url = "www.exchangerate-api.com/zar/jpy?k=API_KEY"
Dim inStream As StreamReader
Dim webRequest As WebRequest
Dim webresponse As WebResponse
webRequest = webRequest.Create(url)
webresponse = webRequest.GetResponse()
inStream = New StreamReader(webresponse.GetResponseStream())
answer = inStream.ReadToEnd()
Error Codes:
The API returns the following error codes:-1 if an invalid amount is used (must be numeric floating point or integer numbers)
-2 if either of the 3 letter currency codes are invalid (Check our supported currencies)
-3 if an invalid key is used (Get an API key)
-4 if your monthly API query limit is reached (Click here for extended usage)
-5 if an unresolvable IP address is provided (This only applies for our "Automatic Country/Flag Information" query.)
We also offer two additional types of query:
2. Automatic Currency Detection/Conversion (in ASP.NET):
To convert from 12.50 USD (US Dollar) to your user's currency:
Dim url As String
Dim ip As String
ip = Request.ServerVariables("REMOTE_ADDR")
url = "www.exchangerate-api.com/auto/USD/"+ip+"/12.50?k=API_KEY"
Dim inStream As StreamReader
Dim webRequest As WebRequest
Dim webresponse As WebResponse
webRequest = webRequest.Create(url)
webresponse = webRequest.GetResponse()
inStream = New StreamReader(webresponse.GetResponseStream())
result = inStream.ReadToEnd()
Dim return_array() As String
results() = result.Split("|")
Dim converted_amount As Double = results(0) 'FINAL CONVERTED AMOUNT
Dim symbol_unicode As String = results(1) 'FINAL DECIMAL UNICODE FOR SYMBOL
Dim currency_code As String = results(2) 'FINAL 3-DIGIT CURRENCY CODE (EG: USD)
'If you want to display the currency's symbol in HTML:
Dim symbol_html As String = "";
Dim symbol_characters() As String
symbol_characters = symbol_unicode.Split("|")
Dim i As Integer
For i = 0 To symbol_characters.Length - 1
symbol_html = symbol_html+""+symbol_characters(i)+";"
Next i
3. Automatic Country/Flag Information (in ASP.NET):
To retrieve your user's national flag and other country information:
Dim url As String
Dim ip As String
ip = Request.ServerVariables("REMOTE_ADDR")
url = "www.exchangerate-api.com/country_info/"+ip+"?k=API_KEY"
Dim inStream As StreamReader
Dim webRequest As WebRequest
Dim webresponse As WebResponse
webRequest = webRequest.Create(url)
webresponse = webRequest.GetResponse()
inStream = New StreamReader(webresponse.GetResponseStream())
result = inStream.ReadToEnd()
Dim return_array() As String
results() = result.Split("|")
Dim country_name As String = results(0) 'FINAL COUNTRY NAME
Dim country_code_2 As String = results(1) 'FINAL 2-DIGIT COUNTRY CODE (EG: US)
Dim country_code_3 As String = results(2) 'FINAL 3-DIGIT COUNTRY CODE (EG: USA)
Dim currency_code As String = results(3) 'FINAL 3-DIGIT CURRENCY CODE (EG: USD)
Dim symbol_unicode As String = results(4) 'FINAL DECIMAL UNICODE FOR SYMBOL
Dim flag_url As String = results(5) 'FINAL URL FOR FLAG IMAGE
'If you want to display the currency's symbol in HTML:
Dim symbol_html As String = "";
Dim symbol_characters() As String
symbol_characters = symbol_unicode.Split("|")
Dim i As Integer
For i = 0 To symbol_characters.Length - 1
symbol_html = symbol_html+""+symbol_characters(i)+";"
Next i
How Our API Works
Python
PHP
Ruby
Perl
ASP.NET
Java
Applescript
iPhone C