2013-09-21 118 views
0

我有其他表單帖子可以正常工作,但由於某種原因,這一個用於引發「System.ArgumentException:值不在預期範圍內」。信息。HttpClient.PostAsync - 爲什麼會拋出一個ArgumentException

什麼可能是錯的?

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

} 

回答

2

啊,顯然一個空字符串不是HttpStringContent的有效值。

+0

thx,想知道爲什麼我得到這個錯誤......;) – mech

相關問題