基本上,这是每当单击wpf按钮时执行的方法:
private void Dial(object sender, RoutedEventArgs e)
{
SendDataAsync(sender, e);
}
private async Task SendDataAsync(object sender, RoutedEventArgs e)
{ //this method does the actual dialing part
var toSend = new Dictionary<string, string>
{
{ "ClientID", ConfigurationManager.AppSettings["ClientID"] },
{ "PhoneNumber", numberToSend }
};
string jsonString = JsonSerializer.Serialize(toSend);
var content = new StringContent(jsonString);
content.Headers.Add("Content-type", "text/json");
content.Headers.Add("Content-type", "application/json");
var response = await client.PostAsync("https://webhook.site/4788266d-9caf-4747-a3d2-09777b233435", content);
var responseString = await response.Content.ReadAsStringAsync();
}
我已经尝试注解掉“content.headers.add”行,但错误仍然存在
EDIT:这是debug输出中显示的完整异常:抛出异常:System.Net.Http.dll中的“System.FormatException”
1条答案
按热度按时间axr492tv1#
从评论中复制,以便我可以将此问题标记为已回答:“你不能有两种内容类型。你可以用PostAsJsonAsync替换所有这些代码,例如await client.PostAsJsonAsync(url,toSend);”
编辑:哎呀nvm它不会让我抱歉