-2

I have got some code in here that getting world currency exchanges from net. But in following code, this line

private double GetConvertedCurrencyValue(string inputCurrency, string outputCurrency, double value) 
{
    string request = String.Format("http://www.xe.com/ucc/convert.cgi?Amount={0}&From={1}&To={2}", value, inputCurrency, outputCurrency);

    System.Net.WebClient wc = new System.Net.WebClient();
    string apiResponse = wc.DownloadString(request);    // This is a blocking operation.
    wc.Dispose();


    string header = String.Format("XE.com: {0} to {2} rate:",inputCurrency, outputCurrency);


    apiResponse = apiResponse.Replace(header, "");


    string outValue = apiResponse.Split('=')[1];


    outValue = outValue.Replace(outputCurrency, "");

    return Double.Parse(outValue, System.Globalization.CultureInfo.InvariantCulture);
}

was error. What can I do?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Falcon
  • 7
  • 3

1 Answers1

0

In this line of code you have:

string header = String.Format("XE.com: {0} to {2} rate:",inputCurrency, outputCurrency);

It should be:

string header = String.Format("XE.com: {0} to {1} rate:",inputCurrency, outputCurrency);
Dev
  • 1,780
  • 3
  • 18
  • 46
  • thank you but now it is error - return Double.Parse(outValue, System.Globalization.CultureInfo.InvariantCulture); – Falcon Oct 02 '17 at 10:15
  • What error are you getting? You need you specify the error so the community can help you. – Dev Oct 02 '17 at 10:17
  • It gave me "Input string is not correct format". If you have another code for this solution please share. – Falcon Oct 02 '17 at 10:21
  • This Means that whatever is in `outValue` is not compatible to be Convert to a double. Put a breakpoint on `string outValue = apiResponse.Split('=')[0];` and step through it and you will see what I mean. make sure you are parsing the API response correctly or have the right permissions? – Dev Oct 02 '17 at 11:04
  • I just want such a method that gets data from internet. For example https://en.cbar.az/other/azn-rates?act=fetchForm&date%5Bday%5D=2&date%5Bmonth%5D=10&date%5Byear%5D=2017 from this link for exchanges – Falcon Oct 02 '17 at 11:10
  • Check out [Matthiee](https://stackoverflow.com/a/43573923/5326036) answer. It might be useful. – Dev Oct 02 '17 at 11:21