我正在尝试从USD转换为PKR,但没有一个api在起作用。我也尝试过yahoo和google。它们现在还免费吗?
google api正在使用禁止的远程访问来响应错误。 并且yahoo api正在与远程服务器进行响应。
请给我一些其他免费的解决方案。
共享下面的代码。
public string CurrencyConversion(decimal amount, string fromCurrency, string toCurrency)
{
const string urlPattern = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1";
string url = string.Format("https://www.google.com/finance/converter?a={2}&from={0}&to={1}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);
using (var wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
WebClient web = new WebClient();
string response = wc.DownloadString(url);
var split = response.Split((new string[] { "<span class=bld>" }), StringSplitOptions.None);
var value = split[1].Split(' ')[0];
decimal rate = decimal.Parse(value, CultureInfo.InvariantCulture);
return "";
}
}