POST 405(方法不允许)

时间:2015-11-16 10:37:15

标签: javascript ajax http-headers xmlhttprequest box

我正在尝试构建一个使用BOX API的Chrome扩展程序。

我能够对应用程序进行身份验证和启用访问,然后从URL中提取并存储访问令牌。

下一步是将文件上传到框中,我正在尝试使用他们在网站上提供的代码进行少量修改:

//file - a csv file I created before

var uploadUrl = 'https://upload.box.com/api/2.0/files/General';

// The Box OAuth 2 Header. Add your access token.
var headers = {
    Authorization: 'Bearer '+localStorage.authorization_token
};

$.ajax({
    url: uploadUrl,
    headers: headers,
    type: 'POST',
    // This prevents JQuery from trying to append the form as a querystring
    processData: false,
    contentType: false,
    data: link
}).complete(function ( data ) {
    // Log the JSON response to prove this worked
    console.log(data.responseText);
});

但是在运行代码时它会给我以下错误:

405(不允许的方法)

POST https://upload.box.com/api/2.0/files/General 405 (Method Not Allowed)k.cors.a.crossDomain.send @ jquery.js:4n.extend.ajax @ jquery.js:4downloadCSV @ content.js:351(anonymous function) @ content.js:276 content.js:361

注意:我联系了api@box.com,他们说他们为我的帐户启用了CORS

在我的manifest.json中,我有"permissions": ["tabs", "<all_urls>","storage" , "alarms" ]

0 个答案:

没有答案