dropbox-sdk-dotnet: HTTP 400 Bad Request On Download

The server now returns an HTTP 400 Bad Request on a files/download call to the API because of missing Content-Type.

In DropboxRequestHandler.cs, line 443, the Content type for RouteStyle.Download is set to null while the server needs at least a text/plain.

I simply removed the line setting the Content-Type null and it worked with the default Content-Type value. I guess the long term solution should be more in line with the API requirements.

`case RouteStyle.Download: request.Headers.Add(DropboxApiArgHeader, requestArg);

                // This is required to force libcurl remove default content type header.
                request.Content = new StringContent("");
                //request.Content.Headers.ContentType = null;

                completionOption = HttpCompletionOption.ResponseHeadersRead;
                break;

`

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Thanks! In addition, I think the problem originates from Xamarin using the “AndroidClientHandler” as HttpMessageHandler. So using the current lib version, a workaround would be explicitly setting the (less efficient) HttpClientHandler dbx = new DropboxClient(accessToken, new DropboxClientConfig() { HttpClient = new HttpClient(new HttpClientHandler()) });

It appears that my previously posted workaround stopped working after migrating my project to a Android .NET6.

I now was able to implement an alternative workaround:

public class MyAndroidMessageHandler : AndroidMessageHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        if (request.RequestUri.AbsolutePath.Contains("files/download"))
        {
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
        }
        return base.SendAsync(request, cancellationToken);
    }
}

dbx = new DropboxClient(accessToken, new DropboxClientConfig() { HttpClient = new HttpClient(new MyAndroidMessageHandler()) });

@greg-db would it be possible to fix this in the SDK as suggested here? I can also provide a demo project if that helps you reproducing the problem

@greg-db Fwiw thought I would leave a note here that I ran into this issue today with a Xamarin.Forms Android Application - thanks to the last comment from @tipa, using HttpClientHandler seems to have solved the problem for me…