0

我在将表单发布到 MVC 时遇到问题,但仅当站点托管在 azure 中时。当它本地托管在 IIS 内部或计算模拟器内部时,它可以正常工作。

请求已发布,但表单中的字段未映射到操作的参数。

我需要对 azure 部署做些什么时髦的事情吗?

MultipartFormDataContent data = new MultipartFormDataContent();
if (!String.IsNullOrEmpty(about))
{
    data.Add(new StringContent(about), "about");
}
data.Add(new StringContent(displayName), "displayName");
data.Add(new StringContent(name), "name");
data.Add(new StringContent(email), "email");
data.Add(new StringContent(phone), "phone");
data.Add(new StringContent(isPublic ? "true": "false"), "isPublic");
data.Add(new StringContent(isPrimary ? "true" : "false"), "isPrimaryProfile");
if (picture != null)
{
    byte[] imageBytes = await picture.GetBtyeFromFile();
    string imageString = Convert.ToBase64String(imageBytes);
    data.Add(new StringContent(imageString), "picture");
}

Uri uri = new Uri(url, UriKind.Absolute);
HttpResponseMessage responseMessage = await client.PostAsync(uri, data);

在服务器端,一切似乎都正确到达。这是我从 InputStream 中提取的主体:

--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=displayName

display
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=name

Test Seller Account
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=email

email
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=phone

phone
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=isPublic

false
--614f8827-0cfe-48a6-a819-e6e9acdccae0
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=isPrimaryProfile

true
--614f8827-0cfe-48a6-a819-e6e9acdccae0--

并且是标题:

ALL_RAW - Content-Length: 880
Content-Type: multipart/form-data; boundary="614f8827-0cfe-48a6-a819-e6e9acdccae0"
Host: [my server]
4

1 回答 1

3

请参阅:如何使用 .Net 4.0 中包含的 HttpClient 类将文件上传到在 IIS Express 中运行的 Asp.Net MVC 4.0 操作

基本上,您必须引用您的参数名称:

data.Add(new StringContent(displayName), @"""displayName""");
于 2014-02-19T08:02:19.997 回答