我有以下表单页面将文件上传到服务器。服务器要求完成身份验证并立即发送401 Unauthorized以响应POST请求。但是,浏览器IE,Chrome和Firefox都忽略了401并继续发布数据并最终超时。我希望浏览器弹出登录窗口。我做错了什么!?
POST请求
Http: Request, POST /cgi/upload
Command: POST
URI: /cgi/upload
ProtocolVersion: HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://x.x.x.x/configuration/uploadImgfile.html?0
Accept-Language: en-US
UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)
+ ContentType: multipart/form-data; boundary=---------------------------7de3c75d0a52
Accept-Encoding: gzip, deflate
Host: 16.93.62.215
ContentLength: 7866893
Connection: Keep-Alive
Cache-Control: no-cache
HeaderEnd: CRLF
server 401 reply
Http: Response, HTTP/1.1, Status: Unauthorized,
URL: /cgi/upload ,
Using Basic realm="XXXXX" Authentication
ProtocolVersion: HTTP/1.1
StatusCode: 401, Unauthorized
Reason: Unauthorized
Server: eHTTP v2.0
Connection: close
+ WWWAuthenticate: Basic realm="XXXXX"
HeaderEnd: CRLF
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Update Software</title>
<script type="text/javascript">
function getlocation(){
var url=window.location.href;
var test=url.split("?");
test=test[1];
if(test == 0)
document.sti.location.value="primary";
else
document.sti.location.value="secondary";
}
</script>
</head>
<body onLoad="getlocation();">
<table border="0" align=center cellpadding="50">
<tr>
<td>
<form name="sti" action="../cgi/upload" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input name="location" type="hidden"/>
You can upload an Image.<p>
File: <input name="imagefile" type="file"/><br/>
<input name="reboot" type="checkbox" value="Reboot" checked />reboot
</p>
<input type="submit" name="submit" value="Upload"/>
<input type="button" name="cancel" value="Cancel" onClick="document.location='../configuration/configfilef.html';"/>
</form>
</td></tr></table>
</body>
</html>