This project is read-only.
1
Vote

OAuth的UriBuilder使用错误

description

代码中
internal string Request(string url, RequestMethod method = 0, params WeiboParameter[] parameters)
{
UriBuilder uri = new UriBuilder(url);
string result = string.Empty;
bool multi = false;
multi = parameters.Count<WeiboParameter>(p => p.IsBinaryData) > 0;
switch (method)
{
    case RequestMethod.Get:
        uri.Query = Utility.BuildQueryString(parameters);
        break;

    case RequestMethod.Post:
        if (!multi)
        {
            uri.Query = Utility.BuildQueryString(parameters);
        }
        break;
}
if (string.IsNullOrEmpty(this.AccessToken))
{
    if (uri.Query.Length == 0)
    {
        uri.Query = "source=" + this.AppKey;
    }
    else
    {
        __uri.Query = uri.Query + "&source=" + this.AppKey;__
    }
}

但是根据MSDN文档 , Query属性不能这样设置
Note Do not append a string directly to this property. If the length of Query is greater than 1, retrieve the property value as a string, remove the leading question mark, append the new query string, and set the property with the combined string.



Copy
        UriBuilder baseUri = new UriBuilder("http://www.contoso.com/default.aspx?Param1=7890");
        string queryToAppend = "param2=1234";

        if (baseUri.Query != null && baseUri.Query.Length > 1)
            baseUri.Query = __baseUri.Query.Substring(1) + "&" + queryToAppend;__ 
        else
            baseUri.Query = queryToAppend;

comments