c# - HttpClient PostAsync Invalid Post Format -
i trying use httpclient's postasync login website; fails , when tracked connection using wireshark found posts data incorrectly
code
var content = new formurlencodedcontent(new[] { new keyvaluepair<string, string>("value1", data1), new keyvaluepair<string, string>("value2", data2), new keyvaluepair<string, string>("value3", data3) });
or
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) };
usage
httpclient.postasync(posturi, content)
expectations
value1=123456&value2=123456&value3=123456
reality
//it adds strange += makes post fail... value1=123456&value2+=123456&value3+=123456
i know works:
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) }
Comments
Post a Comment