添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Forum Discussion

PoisonIvy
New member | Level 2
6 years ago

CORS Error HTTP API using Ajax

So I'm new to the Dropbox API and I've been experimenting with HTTP API calls using javascript's Ajax function. I'm currently trying to use the /create functionality but I'm encountering a CORS error.

Here's the code I'm using:

const title = "more_examples.txt";
	const destination = "/";
	const response = $.ajax({
		url: "https://api.dropboxapi.com/2/file_requests/create",
type: "POST",
dataType: 'application/octet-stream',
async: false,
headers: {
"Authorization": "Bearer <TOKEN>",
"Content-Type": "application/json",
"data": '{"title": "' + title + '","destination": "' + destination + '","deadline": {"deadline": "2020-10-12T17:00:00Z","allow_late_uploads": "seven_days"},
"open": true}'
}
});

And here's the error:

Cross-Origin Request Blocked: The Same Origin Policy disallows
reading the remote resource at https://dl.dropboxusercontent.com/2/file_requests/create.
(Reason: CORS request did not succeed).

To make matters worse, I had previously tried downloading a file and that totally worked! Here's that code too:

        const path = "example.txt";
const args = { "path": path const response = $.ajax({ url: "https://content.dropboxapi.com/2/files/download", type: "POST", dataType: 'application/octet-stream', async: false, headers: { "Authorization": "Bearer <TOKEN>",