HttpClient.PostAsync - 为什么会抛出ArgumentException

时间:2013-09-21 00:05:40

标签: windows-8 windows-runtime winrt-xaml windows-8.1

我有其他表单帖子可以正常工作,但由于某种原因,这个用于抛出“System.ArgumentException:Value不在预期范围内”。消息。

可能出现什么问题?

using (HttpClient client = new HttpClient())
{
    HttpMultipartFormDataContent data = new HttpMultipartFormDataContent();
    data.Add(new HttpStringContent(about ?? String.Empty), "about");
    data.Add(new HttpStringContent(displayName ?? String.Empty), "name");
    data.Add(new HttpStringContent(email ?? String.Empty), "email");
    data.Add(new HttpStringContent(firstName ?? String.Empty), "firstName");
    data.Add(new HttpStringContent(lastName ?? String.Empty), "lastName");
    data.Add(new HttpStringContent(phone ?? String.Empty), "phone");
    data.Add(new HttpStringContent(isPublic.ToString()), "isPublic");
    data.Add(new HttpStringContent("true"), "isPrimaryProfile");

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

}

1 个答案:

答案 0 :(得分:2)

啊,显然空字符串不是HttpStringContent的有效值。