我将使用Tastypie创建一个API,并希望从Backbone访问该API。为了发送凭据,我使用用户ID和API密钥。在Android中和使用curl时这个方法非常有效,但是我无法从Backbone设置HTTP标头。
在curl中,我使用:
在curl中,我使用:
curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -H "user_id: 32" -H "api_key: 69950" -X DELETE "http://127.0.0.1:8000/api/v1/deletenote/66/?format=json"
在 Android Java 中,我使用:
HttpDelete requestDELETE = new HttpDelete();
requestDELETE.setHeader("Content-type", "application/json");
requestDELETE.setHeader("Accept", "application/json");
requestDELETE.setHeader(Constants.HEADER_USER_ID, user_id);
requestDELETE.addHeader(Constants.HEADER_API_KEY, key);
这两种方法都很好,但是当我尝试在Backbone中使用时,按照页面上其他帖子的响应尝试后,它却无法工作。
我正在尝试这样做:
var removeNote = new DeleteNoteModel({id:this.model.toJSON().id},{ query:this.model.toJSON().id});
removeNote.destroy({
headers: {'user_id':dataWeb.get("id"),'api_key':dataWeb.get("api_key")}
},{
async:false,
error: function(model, response){
console.log("KO_REMOVE_NOTE");
console.log(response);
},
success : function(model, response){
console.log("OK_REMOVE_NOTE");
console.log(response);
}
}
);
当我调用destroy方法时,我在请求头中添加了header,但是服务器并没有接收到任何内容。
我做错了什么?
感谢大家。