简体   繁体   English

DotNetOpenAuth使用者发布大型数据; “ Uri字符串太长”

[英]DotNetOpenAuth consumer POSTing large data; “The Uri string is too long”

Related: DotNetOpenAuth I Need Send Long string in FetchResponse and OpenId query length issue in DotNetOpenAuth? 相关: DotNetOpenAuth我需要在DotNetOpenAuth中在FetchResponseOpenId查询长度问题中 发送长字符串 吗? - but neither of these are able to answer my question satisfactorily. -但是这些都不能令人满意地回答我的问题。

We are using DotNetOpenAuth to post data to Xero, which supports a maximum of 3MB per request . 我们使用DotNetOpenAuth将数据发布到Xero,每个请求最多支持3MB We are trying to post a 77Kb XML string in requestBody : 我们正在尝试在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 is throwing: Invalid URI: The Uri string is too long. PrepareAuthorizedRequest抛出: Invalid URI: The Uri string is too long.

Is there any way I can POST "large" data with DotNetOpenAuth? 有什么方法可以使用DotNetOpenAuth发布“大”数据?

DotNetOpenAuth uses Uri.HexEscape() and Uri.EscapeDataString() on the additional parameters . DotNetOpenAuth在其他参数上使用Uri.HexEscape()Uri.EscapeDataString() This breaks when your parameters are over 2Kb in length. 当您的参数长度超过2Kb时,这会中断。

I have swapped out their function for my own inefficient, but working, function: 我将它们的功能换成了我自己效率低下但可以正常工作的功能:

    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();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM