I'm trying to download a PDF file from the net. The downloaded file is an HTML file (cannot be opened with Adobe Reader). The download is done with result 200.
string tempFile = System.IO.Path.GetTempFileName();
tempFile = System.IO.Path.ChangeExtension(tempFile, "pdf");
HttpResponseMessage msg;
using (HttpClient client = new HttpClient())
{
msg = await client.GetAsync($"https://www.anaf.ro/StareD112/ObtineRecipisa?numefisier=217776607.pdf");
if (msg.IsSuccessStatusCode)
{
using (var file = File.Create(tempFile))
{
var contentStream = await msg.Content.ReadAsStreamAsync();
await contentStream.CopyToAsync(file);
await file.FlushAsync();
}
}
}
The downloaded file has the content:
<!DOCTYPE html><html><head><meta http-equiv="Pragma" content="no-cache"/><meta http-equiv="Expires" content="-1"/><meta http-equiv="CacheControl" content="no-cache"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><link rel="shortcut icon" href="data:;base64,iVBORw0KGgo="/><script>(function(){window["bobcmn"] = "111111101...})();</script><script type="text/javascript" src="/TSPD/08b919fd7aab2000e3f4522c0108677748c289d7a5e2904fcfef59fb022a19a5fd44f0a0664ad54a?type=10"></script><noscript>Please enable JavaScript to view the page content.<br/>Your support ID is: 10865965003120525066.</noscript>
Can you tell me what I'm not doing right?