WebClient :( System.Net.WebException)获取响应流(ReadDone1)时出错:ReceiveFailure

时间:2013-03-28 20:06:57

标签: c# asp.net-mvc xamarin.ios webrequest

这是一个MonoTouch应用程序。我在这个例外的字段中看到了错误。我看到其他SO问题,但似乎没有什么能解决我的问题。这可能与服务器上的maxRequestLength或executionTimeout有关吗?我真的没有想法......

我没有使用WebRequest,我正在使用WebClient。请帮助!

STACK TRACE

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

0 个答案:

没有答案