Forum Discussion

Jim-aacapacity's avatar
Jim-aacapacity
Copper Contributor
Feb 24, 2023

RemoteCertificateNameMismatch when trying to download file

When I try to download a file either by Sharepoint's download url or by using the Graph API (which then automatically redirects to Sharepoint's download url), I get the following exception:

AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 

I have tried many things, such as installing Sharepoint's certificate on my local machine and removing the authorization header of my request (because apparently that is not necessary when calling the download url), but the issue remains the same.

 

When I bypass certificate validation by adding my own HttpClientHandler with a ServerCertificateCustomValidationCallback that always returns true, I get 1 of the following 3 responses, which seem to be selected at random:

1: Some html stating "The resource cannot be found."

2: Some html stating "Our services aren't available right now. We're working to restore all services as soon as possible. Please check back soon."

3: "404 FILE NOT FOUND"

 

If on the other hand I use the Graph API to get information about the file I want to download, everything works just fine and I get a response containing the download url (that currently doesn't work).

 

Here is some code to illustrate the problem:

 

Any suggestion would be greatly appreciated!

  • Found the solution myself: the host header, which is required for other Graph API calls, should be left empty when calling the download url

     

  • Jim-aacapacity's avatar
    Jim-aacapacity
    Copper Contributor

    Found the solution myself: the host header, which is required for other Graph API calls, should be left empty when calling the download url

     

Resources