考虑以下尝试向生成PDF文件的Web服务提交数据:PDF Rocket(顺便说一句,这很棒)。
我得到了错误消息Invalid URI: The uri string is too long
为什么有人会对POST的数据强加任意限制呢?
using (var client = new HttpClient())
{
// Build the conversion options
var options = new Dictionary<string, string>
{
{ "value", html },
{ "apikey", ConfigurationManager.AppSettings["pdf:key"] },
{ "MarginLeft", "10" },
{ "MarginRight", "10" }
};
// THIS LINE RAISES THE EXCEPTION
var content = new FormUrlEncodedContent(options);
var response = await client.PostAsync("https://api.html2pdfrocket.com/pdf", content);
var result = await response.Content.ReadAsByteArrayAsync();
return result;
}
我收到了这个荒谬的错误。
{System.UriFormatException: Invalid URI: The Uri string is too long.
at System.UriHelper.EscapeString
at System.Uri.EscapeDataString
at System.Net.Http.FormUrlEncodedContent.Encode
at System.Net.Http.FormUrlEncodedContent.GetContentByteArray
这使我想起了“640k 应该足够用了…” 我的意思是,真的吗?
JsonConvert.SerializeObject
创建一个JSON字符串,然后使用StringContent
作为字符串内容发送即可。 - IgorHttpClient
类中没有内置的等价方法可以替代WebClient
类中的UploadValues("https://api.html2pdfrocket.com/pdf", options)
方法,是吗? - Jim