问题 HttpClient:uri字符串太长

如果像我一样,你面对的是一些只接受表单内容的第三方网络服务,你可以解决这个问题:

// Let's assume you've got your key-value pairs organised into a nice Dictionary<string, string> called formData
var encodedItems = formData.Select(i => WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value));
var encodedContent = new StringContent(String.Join("&", encodedItems), null, "application/x-www-form-urlencoded");

// Post away!
var response = await client.PostAsync(url, encodedContent);

posted on 2021-03-31 18:44  隨風.NET  阅读(328)  评论(0编辑  收藏  举报

导航