2012-09-12 86 views
5

我正在使用HttpClient。我正在發佈Web表單參數。其中一個價值觀(不是名字)是瑞典的外國人物ö,#246; öASCII:拉丁文小寫字母O變音符號C#HttpClient FormUrlEncodedContent編碼(VS 2012)

手動,IE,Firefox和Chrome都將此字符轉換爲S%F6k,並且一切正常。但VS 2012 C#版本將其轉換爲(通過FormUrlEncodedContent(dict))到%C3%B6

有沒有辦法告訴VS 2012將其轉換爲友好的S%F6k(並且仍然使用HttpClient)?

我已經把它貼的大部分代碼,這可以幫助別人(餅乾,代理等)

// Create Handler 
var handler = new HttpClientHandler(); 

// Cookies 
var cc = new CookieContainer(); 
handler.CookieContainer = cc; 

// Proxy - for fiddler 
WebProxy proxy = new WebProxy(); 
proxy.Address = new Uri("http://localhost:8888"); 
handler.Proxy = proxy; 

// Create the client 
var client = new HttpClient(handler); 

var request4 = new HttpRequestMessage(); 

client.DefaultRequestHeaders.Clear(); 
client.DefaultRequestHeaders.Add("Accept", "text/html, application/xhtml+xml, */*"); 
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate"); 
client.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.8,sv-SE;q=0.5,sv;q=0.3"); 
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"); 

// Form Data 
var dict4 = new Dictionary<string, string> 
{ 
    { "page", "kantlista" }, 
    { "kod", "A0004n" }, 
    { "termin", "H12" }, 
    { "anmkod", "17113" }, 
    { "urval", "ant" }, 
    { "listVal", "namn" }, 
    { "method", "Sök" } // S%F6k 
}; // dict 

request4.Content = new FormUrlEncodedContent(dict4); 

var value4 = new FormUrlEncodedContent(dict4); 
string uri4 = "https://www.ltu.se/ideal/ListaKursant.do"; 
var response4 = await client.PostAsync(uri4, value4); 
response4.Headers.Add("Cache-Control", "no-cache") 
response4.EnsureSuccessStatusCode(); 
string responseBody4 = await response4.Content.ReadAsStringAsync(); 

非常感謝! Todd Booth

+0

'request4'的用途是什麼?看起來它從未使用過。 – MEMark

回答