我正在尝试将此 URL 中的内容获取到我的程序中:https://data.mtgox.com/api/2/BTCUSD/money/ticker https://data.mtgox.com/api/2/BTCUSD/money/ticker。在我的任何浏览器中访问该 URL 时,它都能完美运行。
然而在我的程序中,它等待 90 秒,并给我一个超时。
这是我的代码:
private const string ApiLnk = "https://data.mtgox.com/api/2/BTCUSD/money/ticker";
static void Main(string[] args)
{
using (WebClient client = new WebClient())
{
string s = client.DownloadString(ApiLnk);
int i = 0;
}
}
字符串 s 永远不会被分配,因为 client.DownloadString() 是停滞的。
当获取像 Google.com 这样的普通 URL 时,它工作得很好。
知道出了什么问题吗?
刚刚设置HttpRequestHeader.Accept
and HttpRequestHeader.UserAgent
标头。这有效
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.Accept] = "text/html, image/png, image/jpeg, image/gif, */*;q=0.1";
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12";
string s = client.DownloadString(ApiLnk);
int i = 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)