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


source to share





All Articles