I can download this by hand in IE.
http://scholar.google.com/scholar.ris?q=info:j8ymU9rzMsEJ:scholar.google.com/&output=citation&hl=zh-CN&as_sdt=2000&oe=GB&ct=citation&cd=0
But, using follow code
WebClient client = new WebClient();
client.DownloadFile(address, filename);
Show Exception: 403 Forbidden
What's wrong? How can I do that?
others
http://scholar.google.com/scholar.ris?q=info:sskrpr5jlLwJ:scholar.google.com/&output=citation&hl=zh-CN&as_sdt=2000&oe=GB&ct=citation&cd=1
Double Check the Address. The most common reason for a 403 error is a mistyped URL. First, ensure that the address you are trying to access is for a web page or file, not a directory. For example, a regular URL would end in .com, .
The HTTP 403 Forbidden response status code indicates that the server understands the request but refuses to authorize it. This status is similar to 401 , but for the 403 Forbidden status code, re-authenticating makes no difference. The access is tied to the application logic, such as insufficient rights to a resource.
Just add a simple line before you make your download:
string url = ...
string fileName = ...
WebClient wb = new WebClient();
wb.Headers.Add("User-Agent: Other"); //that is the simple line!
wb.DownloadFile(url, fileName);
That's it.
403 may also be caused by TLS issues. To verify, you should check the text of the WebException.Response object.
catch (WebException ex)
{
if (ex.Response != null)
{
var response = ex.Response;
var dataStream = response.GetResponseStream();
var reader = new StreamReader(dataStream);
var details = reader.ReadToEnd();
}
}
If it is TLS then try adding this to your code to force TLS1.2.
For .net4:
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
For .net4.5 or later:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
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