2011-11-17 57 views
0

如何獲取NameValueCollection值POST的Content-Length?C#在NameValueCollection中發佈值

我正在添加「Content-Length」標題,但不知道要放什麼。

public static string Post (string url, NameValueCollection formData) 
{ 
    string response; 
    int length = formData.??? 

    using (WebClient webClient = new WebClient()) 
    { 
     webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); 
     webClient.Headers.Add ("Content-Length", length); 
     byte[] responseBytes = webClient.UploadValues (url, "POST", formData); 
     response = Encoding.UTF8.GetString (responseBytes); 
    } 

    return response; 
} 
+3

'UploadValues'應該爲你做的該屬性。 – SLaks

+0

根據http://msdn.microsoft.com/en-us/library/system.net.webclient.headers.aspx,您不能使用「WebClient」設置「Content-Length」標頭。 –

回答

0

你不能設置在Web客戶端