相关:DotNetOpenAuth I Need Send Long string in FetchResponse和OpenId query length issue in DotNetOpenAuth? - 但这些都不能令人满意地回答我的问题。
我们正在使用DotNetOpenAuth将数据发布到Xero, which supports a maximum of 3MB per request。我们正尝试在requestBody
中发布一个77Kb的XML字符串:
Dictionary<string, string> additionalParams = new Dictionary<string, string>();
additionalParams.Add("xml",requestBody);
var endpoint = new MessageReceivingEndpoint(requestURL, HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest);
HttpWebRequest request = XeroConsumer.PrepareAuthorizedRequest(endpoint, accessToken, additionalParams);
WebResponse response = request.GetResponse();
string thisResponse = (new StreamReader(response.GetResponseStream())).ReadToEnd();
PrepareAuthorizedRequest
投掷:Invalid URI: The Uri string is too long.
有什么方法可以用DotNetOpenAuth发布“大”数据吗?
答案 0 :(得分:1)
DotNetOpenAuth uses Uri.HexEscape()
and Uri.EscapeDataString()
on the additional parameters。当参数超过2Kb时,这会中断。
我已经将他们的功能换成了我自己效率低下但功能正常的功能:
internal static string EscapeUriDataStringRfc3986(string value)
{
StringBuilder escaped = new StringBuilder();
string validChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._~";
foreach (char c in value)
{
if(validChars.Contains(c.ToString())){
escaped.Append(c);
} else {
escaped.Append("%" + Convert.ToByte(c).ToString("x2").ToUpper());
}
}
// Return the fully-RFC3986-escaped string.
return escaped.ToString();
}