【发布时间】:2015-07-10 22:00:31
【问题描述】:
由于某种原因,当我从我的 xamarin 应用程序发布时,我得到了 500,使用 chrome Advanced Rest Client 我可以发布照片,以便服务正常工作(问题出在应用程序帖子中)...
我的控制器:
public class BlobController : ApiController
{
public Task<List<FileDetails>> Post()
{
if (!Request.Content.IsMimeMultipartContent("form-data"))
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
return FileStorage.StoreFiles(WebConfigurationManager.AppSettings["WebApiContainer"], Request);
}
public class FileDetails
{
public string Name { get; set; }
public long Size { get; set; }
public string ContentType { get; set; }
public string Location { get; set; }
}
我的帖子:
public async Task<FileDetails> PostPhotoRequest(string fileName, MemoryStream file)
{
byte[] response = await _service.PostFileRequest("Blob", fileName, file);
string json = System.Text.Encoding.UTF8.GetString(response, 0, response.Length);
if (string.IsNullOrEmpty(json)) { return new FileDetails(); }
return JsonConvert.DeserializeObject<FileDetails>(json);
}
public async Task<byte[]> PostFileRequest(string url, string filename, MemoryStream file)
{
var client = new HttpClient();
var content = new MultipartFormDataContent("boundary=----WebKitFormBoundaryGQ9UK82gG8XpzEBT");
content.Add(new StreamContent(file));
content.Add(new FormUrlEncodedContent(new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("filename", filename) }));
content.Headers.Add("X-ZUMO-APPLICATION", Constants.MobileServiceApplicationKey);
var response = await client.PostAsync(Constants.MobileServiceUrl + "api/" + url, content);
if (response.StatusCode == HttpStatusCode.OK)
{
byte[] responseContent = await response.Content.ReadAsByteArrayAsync();
return responseContent;
}
return null;
}
响应状态码:内部服务器错误
【问题讨论】:
标签: c# http post xamarin photo