我制作了一个接受PUT
请求的虚拟 django 视图:
# urls.py
url(r'^put/.*$', 'put', name='put'),
# views.py
def put(request):
print request.method
return HttpResponse()
现在,当我尝试对PUT
视图进行 xhr 调用时,它返回 403:
[27/Sep/2012 22:32:43] "PUT /put/x-unconverted/e02ed7da08d411e2bfa974de2b4d1b84?partNumber=115&uploadId=35UxOsGCCG98rke3VjpazmCy.0ZFpesndJ.XPp5Bw6R2CumfIsYKP5DlBYPY3gh3I0PCwfCg4DqSRttYp75bZg-- HTTP/1.1" 403 156400
(为什么它返回 403,我现在不在乎)。真正的问题是:
XHR 调用返回状态 0(中止?!),即使真正的响应是 403,带有内容(注意 156400 内容长度)。
为什么它不显示 403 响应?
编辑:PUT
请求是这样提出的:
var xhr = new XMLHttpRequest();
var path = "/" + u.settings.key;
path += "?partNumber=" + (chunk + 1) + "&uploadId=" + u.upload_id;
var method = "PUT";
var authorization = "AWS " + u.settings.access_key + ":" + signature;
var blob = u.file.slice(start, end); // mozSlice / webkitSlice, depending on browser
xhr.upload.addEventListener("progress", progress_handler);
xhr.addEventListener("readystatechange", handler);
xhr.addEventListener("error", error_handler);
xhr.addEventListener("timeout", error_handler);
xhr.open(method, /*u.settings.host*/ "http://localhost:8000/put" + path, true);
xhr.setRequestHeader("x-amz-date", date);
xhr.setRequestHeader("Authorization", authorization);
xhr.setRequestHeader("Content-Type", u.settings.content_type);
xhr.setRequestHeader("Content-Disposition", "attachment; filename=" + u.file.name);
xhr.send(blob);