Response.Status从myWebClient.UploadFile
问题描述:
我使用这个代码上传文件:Response.Status从myWebClient.UploadFile
WebClient myWebClient = new WebClient();
byte[] responseArray = myWebClient.UploadFile(string.Format("http://{0}/WebApplication/Default.aspx", this.WebServerName), "POST", filePath);
我收到的文件中Page_Load()
:
foreach (string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
Utils.ProcessUpload(file);
Response.Status = "success";
}
我想从responseArray
读取状态所以我可以根据上传状态做出决定。我不知道如何从responseArray
得到Status
。
编辑:示例here没有提供太多帮助。它确实显示响应数组
答
在responseArray只是响应的主体而不是您感兴趣的状态和标题。您可以确定,如果UploadFile方法返回状态将成功2xx或其他。如果响应会4XX(错误)比引发WebException,你可以从异常读取状态:
Check this link how to handle this exception
如果你想更精确的状态处理,你必须直接使用的WebRequest/WebResponse类。