Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried to download PDF from URL and convert it into base64 format. URL is in decoded format.
While using "webClient.DownloadData", it giving me this error:
"The remote server returned an error: (400) bad request."

Can anybody help me on this??

C#
string url ="https://www.sample.com" // url in decode format

using (WebClient webClient = new WebClient())
{
	byte[] imageBytes = webClient.DownloadData(url);
	Convert.ToBase64String(imageBytes);
}


What I have tried:

I tried using WebClient.DownloadFile, but it's giving permission error. Second, I try (HttpWebRequest)WebRequest.Create(url), but it is still giving me the same error.
Posted
Updated 14-Sep-23 2:25am
v3

Simple: there is no site with the URL "www.sample.pdf"
As far as I know, there is no ".pdf" domain at all, which implies that "sample.pdf" is a file, not a website - so you probably need to replace the "http://www." bit with the path to the folder and file in the site.
 
Share this answer
 
Comments
Akshay malvankar 14-Sep-23 1:22am    
sorry typo mistake, and i am download pdf from URL
Either the URL you are requesting does not support a GET request; or you are missing required parameters from your request; or you've hit one of those sites that doesn't work without a "user agent" header[^] set"; or there is something else wrong with the request.

Nobody here can help you. We don't have access to the code running on the site you're trying to download from.

You will need to contact the site admins to determine whether what you are trying to do is possible, and what the cause of the error is. We cannot do that for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900