SOLVED

RemoteCertificateNameMismatch when trying to download file

Copper Contributor

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:

Jimaacapacity_0-1677244530663.png

 

Any suggestion would be greatly appreciated!

1 Reply
best response confirmed by Jim-aacapacity (Copper Contributor)
Solution

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

Jimaacapacity_0-1677588147554.png

 

1 best response

Accepted Solutions
best response confirmed by Jim-aacapacity (Copper Contributor)
Solution

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

Jimaacapacity_0-1677588147554.png

 

View solution in original post