0

I'm trying to make a download request from an API which requires me to include the Base64 String of a PDF in the URL. I'm using the WebClient.DownloadString() method and it gives me a System.IO.PathTooLongException.

I know there's a limit on the characters in the URI (~60k) and my URI are a couple thousand above that, so I don't think setting a base url or anything would help. Is there any way to bypass the URI character limit?

hsbsid
  • 301
  • 1
  • 2
  • 10

1 Answers1

2

I assume the System.IO.PathTooLongException is thrown by the WebClient as a result of a HTTP 414 error? If thats the case, the server does not allow get-requests of that length.

Are you sure that you have to add the pdf data as a GET-parameter? Try POSTing the data like this:

using (WebClient wc = new WebClient())
{
    var nvc = new NameValueCollection();
    nvc.Add("pdf-parameter", "encoded-pdf-here");
    // UploadValues uses 'POST' by default
    var data = wc.UploadValues(url, nvc);
    // Adjust result encoding if required...
    var result = Encoding.UTF8.GetString(data);
}
Michael
  • 1,931
  • 2
  • 8
  • 22
  • I tried using the method from the answer on this question: https://stackoverflow.com/questions/4088625/net-simplest-way-to-send-post-with-data-and-read-response and it works perfect. Thanks for the suggestion. – hsbsid Sep 16 '17 at 16:00