C# HttpStreamContent抛出System.ExecutionEngineeException
我目前正试图通过我的网络服务上传一张图片。我有一段代码:C# HttpStreamContent抛出System.ExecutionEngineeException,c#,windows-phone-8,visual-studio-2013,httpclient,C#,Windows Phone 8,Visual Studio 2013,Httpclient,我目前正试图通过我的网络服务上传一张图片。我有一段代码: public async Task<Webservice> editProfile(List<KeyValuePair<string, string>> values, byte[] image) { String strUrl = String.Format("http://********/nl/webservice/abc123/members/update
public async Task<Webservice> editProfile(List<KeyValuePair<string, string>> values, byte[] image)
{
String strUrl = String.Format("http://********/nl/webservice/abc123/members/update");
var HttpClientUpload = new HttpClient();
HttpMultipartFormDataContent requestUploadContent = new HttpMultipartFormDataContent();
Stream streamImage = new System.IO.MemoryStream(image);
HttpStreamContent streamContent = new HttpStreamContent(streamImage.AsInputStream());
requestUploadContent.Add(streamContent, "myFile", "image.jpg");
foreach (var keyValuePair in values)
{
requestUploadContent.Add(new HttpStringContent(keyValuePair.Value), keyValuePair.Key);
}
HttpResponseMessage responseLogin = await HttpClientUpload.PostAsync(new Uri(strUrl), requestUploadContent);
responseLogin.EnsureSuccessStatusCode();
if (responseLogin.StatusCode == Windows.Web.Http.HttpStatusCode.Ok && responseLogin.Content != null)
{
var data = new Webservice { Status = responseLogin.StatusCode };
data.Data = await responseLogin.Content.ReadAsStringAsync();
Debug.WriteLine(data.Data);
return data;
}
return new Webservice { Status = new Windows.Web.Http.HttpStatusCode() };
}
有人能帮忙吗,已经为这个问题挣扎了好几天了
提前谢谢
编辑
我已更改了我的功能:
public async Task<Webservice> editProfile(List<KeyValuePair<string, string>> values, byte[] image)
{
try
{
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = iso.OpenFile("image.jpg", FileMode.Open, FileAccess.Read))
{
String strUrl = String.Format("http://membr.sanmax.be/nl/webservice/abc123/members/update");
HttpMultipartFormDataContent requestUploadContent = new HttpMultipartFormDataContent();
//Stream streamImage = new System.IO.MemoryStream(stream);
HttpStreamContent streamContent = new HttpStreamContent(stream.AsInputStream());
requestUploadContent.Add(streamContent, "picture", "photo.jpg");
foreach (var keyValuePair in values)
{
requestUploadContent.Add(new HttpStringContent(keyValuePair.Value), keyValuePair.Key);
}
HttpResponseMessage responseLogin = await httpClient.PostAsync(new Uri(strUrl), requestUploadContent);
responseLogin.EnsureSuccessStatusCode();
if (responseLogin.StatusCode == Windows.Web.Http.HttpStatusCode.Ok && responseLogin.Content != null)
{
var data = new Webservice { Status = responseLogin.StatusCode };
data.Data = await responseLogin.Content.ReadAsStringAsync();
Debug.WriteLine(data.Data);
return data;
}
}
}
}
catch (Exception e)
{
Debug.WriteLine(e);
}
return new Webservice { Status = new Windows.Web.Http.HttpStatusCode() };
}
异常消息是什么?未知模块中发生类型为“System.ExecutionEngineeException”的未处理异常。是否存在任何内部异常?奇怪的是,有时它不会失败,有时它会因上述异常而失败。“内部异常”是什么意思?.NET中的@StefGeelen异常具有
InnerException
属性。有时它是空的,但有时它有一个值(另一个异常,它本身可以有自己的InnerException
),这对确定发生了什么至关重要。通常,一个过于通用的异常会明确地告诉您检查InnerException
。
public async Task<Webservice> editProfile(List<KeyValuePair<string, string>> values, byte[] image)
{
try
{
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = iso.OpenFile("image.jpg", FileMode.Open, FileAccess.Read))
{
String strUrl = String.Format("http://membr.sanmax.be/nl/webservice/abc123/members/update");
HttpMultipartFormDataContent requestUploadContent = new HttpMultipartFormDataContent();
//Stream streamImage = new System.IO.MemoryStream(stream);
HttpStreamContent streamContent = new HttpStreamContent(stream.AsInputStream());
requestUploadContent.Add(streamContent, "picture", "photo.jpg");
foreach (var keyValuePair in values)
{
requestUploadContent.Add(new HttpStringContent(keyValuePair.Value), keyValuePair.Key);
}
HttpResponseMessage responseLogin = await httpClient.PostAsync(new Uri(strUrl), requestUploadContent);
responseLogin.EnsureSuccessStatusCode();
if (responseLogin.StatusCode == Windows.Web.Http.HttpStatusCode.Ok && responseLogin.Content != null)
{
var data = new Webservice { Status = responseLogin.StatusCode };
data.Data = await responseLogin.Content.ReadAsStringAsync();
Debug.WriteLine(data.Data);
return data;
}
}
}
}
catch (Exception e)
{
Debug.WriteLine(e);
}
return new Webservice { Status = new Windows.Web.Http.HttpStatusCode() };
}
WinRT information: Response status code does not indicate success: 413 (Request Entity Too Large).
System.Exception: Request entity too large (413).