Skip to content

Commit

Permalink
Merge pull request #2 from SyncfusionExamples/download_image
Browse files Browse the repository at this point in the history
Set the User-Agent header to mimic a request from a browser
  • Loading branch information
sivaramgunabalan authored Aug 22, 2024
2 parents 7428e42 + c72facb commit 5bfc7b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public static Stream DownloadImage(string url)
{
using (WebClient client = new())
{
// Set the User-Agent header to mimic a request from a browser
client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
byte[] imageBytes = client.DownloadData(url);
return new MemoryStream(imageBytes);
}
Expand Down
8 changes: 4 additions & 4 deletions Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
@{Html.BeginForm("ExportToPDF", "Home", FormMethod.Post);
{
<h6>Enter the Blog URL</h6>
@Html.TextBoxFor(model => model.BlogLink, new { style = "margin-bottom: 20px;" })
@Html.TextBoxFor(model => model.BlogLink, new { style = "margin-bottom: 20px; width: 52%;" })

<h6>Enter the Blog Title</h6>
@Html.TextBoxFor(model => model.HeaderText, new { style = "margin-bottom: 20px;" })
@Html.TextBoxFor(model => model.HeaderText, new { style = "margin-bottom: 20px; width: 52%;" })

<h6>Enter the Blog Ad Image URL</h6>
@Html.TextBoxFor(model => model.ImageURL, new { style = "margin-bottom: 20px;" })
@Html.TextBoxFor(model => model.ImageURL, new { style = "margin-bottom: 20px; width: 52%;" })

<h6>Enter the Download URL</h6>
@Html.TextBoxFor(model => model.AdURL, new { style = "margin-bottom: 20px;" })
@Html.TextBoxFor(model => model.AdURL, new { style = "margin-bottom: 20px; width: 52%;" })

<div>
<input type="submit" value="Convert HTML to PDF" style="width:200px;height:27px" />
Expand Down

0 comments on commit 5bfc7b3

Please sign in to comment.