{"id":447,"date":"2012-06-06T16:33:02","date_gmt":"2012-06-06T08:33:02","guid":{"rendered":"http:\/\/www.aoisnow.net\/blog\/?p=447"},"modified":"2012-06-06T16:33:02","modified_gmt":"2012-06-06T08:33:02","slug":"day-2317-vb-net-urlencode-for-oauth","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/447","title":{"rendered":"Day 2317 VB.Net URLEncode for OAuth"},"content":{"rendered":"<p>\u4e4b\u524d\u4e00\u76f4\u7528\u81ea\u5df1\u5199\u7684URLEncode\u65b9\u6cd5\uff0c\u4f46\u5bf9\u4e8eUTF-8\u7684\u5b57\u7b26\u5904\u7406\u4e0d\u592a\u597d\uff0c\u52c9\u5f3a\u80fd\u7528\uff0c\u6700\u8fd1\u6d4b\u8bd5\u996d\u76d2\u7684\u641c\u7d22\u529f\u80fd\u65f6\u53d1\u73b0\u52c9\u5f3a\u80fd\u7528\u5c31\u7b49\u4e8e\u4e0d\u80fd\u7528\uff08\u5bf9\u6c49\u5b57\u7684\u7f16\u7801\u5b8c\u5168\u4e0d\u5bf9\uff09\uff0c\u53ea\u597d\u91cd\u65b0\u628aHTTPUtility.URLEncode\u5f15\u5165\u8fdb\u6765\uff0c\u7136\u540e\u5bf9\u5176\u4e0d\u6b63\u786e\u7684\u5904\u7406\u8fdb\u884c\u4fee\u6b63\u3002<br \/>\n\u4ee5\u4e0b\u4e3a\u76f8\u5e94\u4ee3\u7801\uff0c\u6709\u4e24\u70b9\u8981\u6ce8\u610f\uff1a<br \/>\n1. \u9700\u8981\u5148\u884c\u6dfb\u52a0System.Web\u7684\u5f15\u7528\uff0c\u5982\u679c\u627e\u4e0d\u5230\u8fd9\u4e2a\u5f15\u7528\uff0c\u68c0\u67e5\u76ee\u6807Framework\u662f\u4e0d\u662f\u7528\u4e86Client Profile\u3002<br \/>\n2. \u6700\u540e\u4e00\u6b21\u5c06%253D\u66ff\u6362\u4e3a%3D\u7528\u4e8e\u5c06\u4e8c\u6b21\u7f16\u7801\u7684\u300c=\u300d\u7b26\u53f7\uff08\u7f16\u7801\u540e\u4e3a%3D\uff0c\u4e8c\u6b21\u7f16\u7801\u540e\u4e3a%253D\uff09\u66ff\u6362\u56de\u4e00\u6b21\u7f16\u7801\u3002\u7406\u8bba\u4e0a\u6309\u7167RFC 5849\u548c\u996d\u5426\u81ea\u5df1\u7684\u6587\u6863\uff0cGET\u65b9\u6cd5\u7684QueryString\u5e94\u5f53\u7ecf\u8fc7\u4e00\u6b21URL Encode\uff0c\u7136\u540e\u5728\u751f\u6210Base String\u7136\u540e\u7b7e\u540d\u7684\u65f6\u5019\u88ab\u4e8c\u6b21\u7f16\u7801\uff0c<span style=\"color:#FF0000\">\u4f46\u996d\u5426\u7684API\u5982\u679c\u5728Base String\u4e2d\u68c0\u6d4b\u5230%253D\u65f6\uff0c\u5c06\u4f1a\u8fd4\u56deInvalid Signature\u9519\u8bef\uff0c\u5e76\u4e14\u7ed9\u51fa\u8ba4\u53ef\u7684Base String\u4e2d\u300c=\u300d\u663e\u793a\u4e3a%3D\uff0c\u4e0d\u77e5\u9053\u662f\u4e0d\u662f\u90e8\u7f72\u65f6\u51fa\u73b0\u7684\u95ee\u9898\u3002<\/span><\/p>\n<pre>Private Function doURLEncode(ByVal s As String) As String\n        'URLEncode function with corrections for OAuth Basestr making\n        s = HttpUtility.UrlEncode(s).Replace(\"+\", \"%20\")\n        'Make the lowercased percent-encoded codes into uppercase\n        s = RegularExpressions.Regex.Replace(s, \"(%[0-9a-f][0-9a-f])\", Function(c) c.Value.ToUpper)\n        'Encode the chars RFC requested to encode but the HTTPUtility.URLEncode didn't\n        s = s.Replace(\"(\", \"%28\").Replace(\")\", \"%29\").Replace(\"$\", \"%24\").Replace(\"!\", \"%21\").Replace(\"*\", \"%2A\").Replace(\"'\", \"%27\")\n        'Decode the char [~] RFC requested NOT to encode but HTTPUtility.URLEncode did\n        s = s.Replace(\"%7E\", \"~\")\n        'Both the RFC and API document did not say [=] is a special character, but the API won't accept %253D.\n        s = s.Replace(\"%253D\", \"%3D\")\n        Return s\n    End Function<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u4e00\u76f4\u7528\u81ea\u5df1\u5199\u7684URLEncode\u65b9\u6cd5\uff0c\u4f46\u5bf9\u4e8eUTF-8\u7684\u5b57\u7b26\u5904\u7406\u4e0d\u592a\u597d\uff0c\u52c9\u5f3a\u80fd\u7528\uff0c\u6700\u8fd1\u6d4b\u8bd5\u996d\u76d2\u7684\u641c\u7d22\u529f\u80fd\u65f6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-447","post","type-post","status-publish","format-standard","hentry","category-sketch"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=447"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/447\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}