这是一个 MonoTouch 应用程序。除了这个例外,我在现场看到了错误。我看到其他 SO questions,但似乎没有什么能解决我的问题。这可能与服务器上的 maxRequestLength 或 executionTimeout 有关吗?我真的没有想法...
我没有使用 WebRequest,我使用的是 WebClient。请帮忙!
堆栈跟踪
System.Net.WebException: Error getting response stream (ReadDone1): ReceiveFailure
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x00000] in <filename unknown>:0
at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.UploadFileCore (System.Uri address, System.String method, System.String fileName, System.Object userToken) [0x00000] in <filename unknown>:0
at System.Net.WebClient.UploadFile (System.Uri address, System.String method, System.String fileName) [0x00000] in <filename unknown>:0
客户端代码 (Monotouch)
public void UploadVideo(Guid organizationId, string path) {
WebClient wc = new WebClient();
var token = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password)));
var authHeader = string.Format("Basic {0}", token);
wc.Headers.Add("Authorization", authHeader);
var resource = string.Format("/organizations/{0}/SyncVideo/", organizationId);
var fi = new FileInfo(path);
wc.UploadFile(restClient.BaseUrl + resource, "POST", path);
wc.Dispose();
}
服务器代码 (ASP.Net MVC3)
[HttpPost, Url("v3/organizations/{organizationId?}/SyncVideo/")]
public virtual JsonResult SyncVideo(HttpPostedFileBase file, Guid? organizationId) {
if (organizationId.IsNull()) throw new HttpNotFoundExecption();
if (organizationId != RESTContext.OrganizationId) throw new HttpNotAuthorizedException();
var basePath = RESTContext.Config.VideoPath;
using (new Impersonator(RESTContext.Config.VideoPathUsername, RESTContext.Config.VideoPathDomain,
RESTContext.Config.VideoPathPassword)) {
if (!Directory.Exists(basePath))
Directory.CreateDirectory(basePath);
file.SaveAs(basePath + @"\" + file.FileName);
}
return JsonSuccess();
}