POST 405(不允许使用方法)


                    

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

我能够验证和启用对应用程序的访问,然后从URL中提取并存储访问令牌。</ p>

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

  // file-我之前创建的csv文件

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

// Box OAuth 2标头。 添加您的访问令牌。
var标头= {
     授权:“ Bearer” + localStorage.authorization_token
};

$ .ajax({
     网址:uploadUrl,
     标头:标头,
     输入:“ POST”,
     //这样可以防止JQuery尝试将表单作为查询字符串追加
     processData:否,
     contentType:false,
     数据链接
})。complete(function(data){
     //记录JSON响应以证明此方法有效
     console.log(data.responseText);
});
</ code> </ pre>

但是在运行代码时,它给了我以下错误:</ p>

405(不允许使用方法)</ p>

POST https://upload.box.com/api/2.0/files/General 405(不允许使用方法)k.cors.a.crossDomain.send @ jquery.js:4n.extend.ajax @ jquery.js:4downloadCSV @ content.js:351(匿名函数)@ content .js:276
content.js:361 </ code> </ p>

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

在manifest.json中,我具有“权限”:[“ tabs”,“ ”,“存储”,“警报”] </ code> </ p>
     </ div>

展开原文

原文

I am trying to build a Chrome Extension that uses the BOX api.

I am able to authentificate and enable access for the app, and then I extract and store the access token from the URL.

The next step would be to upload a file to box, and I am trying to use the code they provided on the website with small modifications:

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

But upon running the code it gives me the following error:

405 (Method Not Allowed)

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

NOTE: I contacted api@box.com and they said they enabled CORS for my account

In my manifest.json I have "permissions": ["tabs", "<all_urls>","storage" , "alarms" ]

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问