Download file from Dropbox using javascript dropbox api

I tried to download a file from Dropbox using Core Api with javascript. Here is the method I wrote.

function downloadFile(path) {
    var url = "https://api-content.dropbox.com/1/files/auto/"+path;
    var result;
    var xhr = new XMLHttpRequest();
    xhr.open("POST", url, false);
    xhr.onreadystatechange = function() {    
        if (xhr.readyState === 4 && xhr.status === 200) {
            result = xhr.responseText;
        }
    }
    xhr.send(path);
}

      

But I always get 400 status. I don't know what happened. I got this below HTML as an answer.

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx</center>
</body>
</html>

      

Edit 1:

  var url = "https://api-content.dropbox.com/1/files/auto/" + path;
    var result;
    var xhr = new XMLHttpRequest();    
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
            result = xhr.responseText;
        }
    }
    xhr.open("GET", url, true);
    xhr.setRequestHeader("access_token",token);
    xhr.send();

      

+3
javascript dropbox xmlhttprequest dropbox-api


source to share


No one has answered this question yet

Check out similar questions:

7649
How does JavaScript blocking work?
7494
How can I remove a specific element from an array in JavaScript?
7432
How to check if a string contains a substring in JavaScript?
7287
What does "use strict" do in JavaScript, and what are the reasons for it?
5722
How can I remove a property from a JavaScript object?
5670
Which operator is equal (== vs ===) should be used in JavaScript comparisons?
5129
How do I return a response from an asynchronous call?
5101
What's the most efficient way to deeply clone an object in JavaScript?
4829
How do I include a JavaScript file in another JavaScript file?
2817
How can I upload files asynchronously?



All Articles
Loading...
X
Show
Funny
Dev
Pics