Post 使用 Flurl 的图像 base64
Post image base64 using Flurl
我正在尝试 post 使用 Flurl 的简单请求。但是有一个例外,因为 takenPicture
字符串太大了。有什么方法可以使用 Flurl post 大字符串吗?
System.UriFormatException: Uri is longer than the maximum 32766 characters.
var postData = BaseAdress.PostUrlEncodedAsync(new {
text = Uri.EscapeDataString(body),
subject = Uri.EscapeDataString(subject),
from_email = from,
recipient_email = to,
picture = takenPicture //Base64 string
});
这个限制虽然有点武断,但是 by design in Microsoft's Uri.EscapeDataString
method, which is commonly used by applications and libraries (including Flurl) to encode data for both URL queries and URL-encoded request bodies. Both Xamarin and RestSharp Portable have dealt with this so I'm sure a work-around is possible and I might consider this in Flurl if you want to create an issue。
但是,请记住 URL- 像图像这样对二进制数据进行编码是非常不寻常的,如果可能的话,good reasons 可以避免这种情况。当然,如果这是您正在使用的第 3 方 API,您就别无选择。但是,如果您可以控制服务器端代码,我建议您重构它以接受 multipart/form-data
。
我正在尝试 post 使用 Flurl 的简单请求。但是有一个例外,因为 takenPicture
字符串太大了。有什么方法可以使用 Flurl post 大字符串吗?
System.UriFormatException: Uri is longer than the maximum 32766 characters.
var postData = BaseAdress.PostUrlEncodedAsync(new {
text = Uri.EscapeDataString(body),
subject = Uri.EscapeDataString(subject),
from_email = from,
recipient_email = to,
picture = takenPicture //Base64 string
});
这个限制虽然有点武断,但是 by design in Microsoft's Uri.EscapeDataString
method, which is commonly used by applications and libraries (including Flurl) to encode data for both URL queries and URL-encoded request bodies. Both Xamarin and RestSharp Portable have dealt with this so I'm sure a work-around is possible and I might consider this in Flurl if you want to create an issue。
但是,请记住 URL- 像图像这样对二进制数据进行编码是非常不寻常的,如果可能的话,good reasons 可以避免这种情况。当然,如果这是您正在使用的第 3 方 API,您就别无选择。但是,如果您可以控制服务器端代码,我建议您重构它以接受 multipart/form-data
。