2
我正在使用HttpClient
進行簡單調用。問題是,它似乎沒有發送我提供的內容。服務器讓我對這個錯誤,當我在看與小提琴手的請求時,它不顯示內容,因爲它應該:什麼可以是錯誤的HttpClient在POST期間不傳遞內容
HttpContent content = new FormUrlEncodedContent(
new List<KeyValuePair<string, string>> {
new KeyValuePair<string, string>("key1", "value1"),
new KeyValuePair<string,string>("key2","value2"),
new KeyValuePair<string,string>("key3","value3"),
new KeyValuePair<string,string>("key4", "value4"),
new KeyValuePair<string, string>("key5", "value5"),
new KeyValuePair<string, string>("key6", "value6")
});
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
content.Headers.ContentType.CharSet = "UTF-8";
HttpResponseMessage resposne = await client.PostAsync(new Uri("my_url"), content);
有什麼建議?
服務器給出了什麼錯誤?請求是什麼樣的? – kasperhj
你的代碼看起來不錯。當你說內容看起來不像應該那樣,你可以解釋它應該是什麼樣子,它與預期輸出有什麼不同? –
不好意思的回答/個人問題......但會改變爲以下幫助嗎? 'content.Headers.ContentType =「application/x-www-form-urlencoded」;' – Jammerz858