返回> 网站首页
[转载]腾讯微博 - 用add_pic发送带汉字的内容时签名错误
yoours2013-04-21 17:23:48
简介一边听听音乐,一边写写文章。
使用下载的C# sdk, 通过add_pic发送微博时,发送全英文和数字的内容正常,只要一带汉字、空格什么的,就会出现{"data":null,"errcode":-111,"msg":"check sign error","ret":3}
要修改sdk 中的GenerateSignatureBase函数,准备signatureBase的时候,要将内容参数编码两次,但是输出的normalizedRequestParameters参数是不能编码的,修改后的GenerateSignatureBase函数如下:
private string GenerateSignatureBase(Uri url, string httpMethod, List<Parameter> parameters, out string normalizedUrl, out string normalizedRequestParameters)
{
normalizedUrl = null;
normalizedRequestParameters = null;
parameters.Sort(new ParameterComparer());
normalizedUrl = string.Format("{0}://{1}", url.Scheme, url.Host);
if (!((url.Scheme == "http" && url.Port == 80) || (url.Scheme == "https" && url.Port == 443)))
{
normalizedUrl += ":" + url.Port;
}
normalizedUrl += url.AbsolutePath;
normalizedRequestParameters = FormEncodeParameters(parameters);
//normalizedRequestParameters = NormalizeRequestParameters(parameters);
StringBuilder signatureBase = new StringBuilder();
signatureBase.AppendFormat("{0}&", httpMethod.ToUpper());
signatureBase.AppendFormat("{0}&", UrlEncode(normalizedUrl));
signatureBase.AppendFormat("{0}", UrlEncode(normalizedRequestParameters));
// 增加即可
normalizedRequestParameters = NormalizeRequestParameters(parameters);
return signatureBase.ToString();
}
文章评论
1627人参与,0条评论