I am trying to get the content from this URL into my program: https://data.mtgox.com/api/2/BTCUSD/money/ticker . When visiting the URL in any of my browsers, it works perfectly.
However in my program, it waits for 90 seconds, and give me a timeout.
This is my code:
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;
}
}
The string s never gets assigned, as the client.DownloadString() is the one stalling.
When getting a normal URL like Google.com, it works perfectly.
Any idea what's wrong?
Just set HttpRequestHeader.Accept
and HttpRequestHeader.UserAgent
headers. This works
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;
}
Add a user-agent to the headers and you should be fine.
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With