question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTTP 400 Bad Request On Download

See original GitHub issue

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;

`

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
tipacommented, Apr 30, 2019

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()) });

1reaction
tipacommented, Jun 12, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix a 400 Bad Request Error (Causes and Fixes)
A 400 Bad Request error is a generic client error that occurs when the server determines that the error doesn't fall in any...
Read more >
How to Fix a 400 Bad Request Error: 8 Easy Methods
Stuck with a 400 bad request error? Read this article to find out 8 simple methods to solve the problem and its possible...
Read more >
HTTP Error 400 Bad Request: What It Is and How to Fix It
The HTTP error 400 Bad Request is a client-side error that can happen when you visit a website. Learn more about the common...
Read more >
How to Fix the 400 Bad Request Error
The 400 Bad Request error means that the request you sent to the website server to view the page was somehow incorrect.
Read more >
What is a Bad Request Error 400 and How Do You Fix It?
You can call it an error 400 message or 400: Bad Request. The error 400 also shows as “HTTP error 400” in some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found