Why does a PUT 403 show up as Aborted?

匆匆过客 提交于 2019-12-08 11:52:22

问题


I've made a dummy django view that accepts PUT requests:

# urls.py
url(r'^put/.*$', 'put', name='put'),

# views.py
def put(request):
    print request.method
    return HttpResponse()

Now, when I try to make a PUT xhr call to the view, it returns a 403:

[27/Sep/2012 22:32:43] "PUT /put/x-unconverted/e02ed7da08d411e2bfa974de2b4d1b84?partNumber=115&uploadId=35UxOsGCCG98rke3VjpazmCy.0ZFpesndJ.XPp5Bw6R2CumfIsYKP5DlBYPY3gh3I0PCwfCg4DqSRttYp75bZg-- HTTP/1.1" 403 156400

(why it returns 403, I don't care right now). The REAL problem is this:

The XHR call returns status 0 (aborted?!), even if the real response was a 403, with content (notice 156400 content length).

Why doesn't it show the 403 response?

EDIT: the PUT request is made like this:

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

回答1:


I think browser is assuming that it is a cross-domain request when it receives 403 which means forbidden access. That's the reason why browser is not handling data back to the javascript code that made the request. Server should send 'Action-Control-Allow-Origin' header for all the responses.



来源:https://stackoverflow.com/questions/12634167/why-does-a-put-403-show-up-as-aborted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!