RestSharp:签名基础生成中的 UrlEncode 返回无效字符串 [英] RestSharp: UrlEncode in signature base generation returns invalid string

查看:53
本文介绍了RestSharp:签名基础生成中的 UrlEncode 返回无效字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 win8 开发 twitter 客户端,使用 RestSharp ( http://restsharp.org/ ) 和我有这样的问题:当我使用 RestClient 发布新推文时

I'm working on twitter client for win8, using RestSharp ( http://restsharp.org/ ) and I have such problem: When I'm posting new tweet with RestClient

var timeLine = new RestRequest("/1/statuses/update.json", Method.POST);
var txt = "Hello world";
timeLine.AddParameter("status", txt);

一切正常,但如果我添加更复杂的状态,如:

everything works excelent, but if I add more complex status like:

var txt = "Hello, World! What a nice day! #1May";
timeLine.AddParameter("status", txt);

我收到 401 错误.在调试器中,我看到签名基字符串中的状态参数不正确.我有:

I recieve 401 error. In debugger I saw, that status parameter in Signature Base String is incorrect. I have:

status%3DHello%2C%2520World%21%2520What%2520a%2520nice%2520day%21%2520%231May

和正确的字符串(来自 dev.twitter.com):

and right string (from dev.twitter.com):

status%3DHello%252C%2520World%2521%2520What%2520a%2520nice%2520day%2521%2520%25231May

你可以看到,标点符号 ,!# 等编码不正确.我该如何解决?签名基础生成和编码位于/Authenticators/OAuth/OAuthTools.cs

You can see, that punctuation marks ,!# and other encodes incorrect. How can I fix it? Signature base generation and Encoding are in /Authenticators/OAuth/OAuthTools.cs

推荐答案

我在网站上显示 Twitter 提要时遇到了同样的问题.因此,我使用此代码来转换文本.

I have the same problem when I display twitter feed in website. Hence, I used this code to convert the text.

Regex.Replace(str, "@(.*?):", @"@http://twitter.com/#!/$1>$1:");

Regex.Replace(str, "@(.*?):", @"@http://twitter.com/#!/$1>$1:");

这篇关于RestSharp:签名基础生成中的 UrlEncode 返回无效字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆