gpt4 book ai didi

c# - HttpClient PostAsync 无效的发布格式

转载 作者:太空狗 更新时间:2023-10-29 19:41:14 24 4
gpt4 key购买 nike

我正在尝试使用 HttpClient 的 PostAsync 登录网站;然而,它总是失败,当我使用 WireShark 跟踪连接时,我发现它发布的数据不正确

代码

var content = new FormUrlEncodedContent(new[] 
{
new KeyValuePair<string, string>("value1", data1),
new KeyValuePair<string, string>("value2", data2),
new KeyValuePair<string, string>("value3", data3)
});

var content = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("value1", data1),
new KeyValuePair<string, string>("value2", data2),
new KeyValuePair<string, string>("value3", data3)
};

用法

httpClient.PostAsync(postUri, content)

期望

value1=123456&value2=123456&value3=123456

现实

//It adds strange += which makes the post fail...
value1=123456&value2+=123456&value3+=123456

最佳答案

我知道这行得通:

var values = new List<KeyValuePair<string, string>>();

values.Add(new KeyValuePair<string, string>("Item1", "Value1"));
values.Add(new KeyValuePair<string, string>("Item2", "Value2"));
values.Add(new KeyValuePair<string, string>("Item3", "Value3"));

using (var content = new FormUrlEncodedContent(values))
{
client.PostAsync(postUri, content).Result)
}

关于c# - HttpClient PostAsync 无效的发布格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17973981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com