1, from the source:
KV needs to parse the URL URLs that came from the plugin because it may be encoded, so it needs to be decoded.
First Use System.Web.HttpUtility.UrlDecode () this function, but according to the user environment crash scene, found that there is a. NET Framework library is not the case, that is, System.Web.dll this assembly is not found.
There is such a thing!
Self-written code parsing, download the system.web source code on the Internet, pull away the required functions, to meet the requirements, the project can discard the reference to System.Web
2, UrlDecode (String str)
Direct code to make memo:
Public Static stringUrlDecode (stringstr) { returnUrlDecode (str, ENCODING.UTF8); } Static voidWritecharbytes (IList buf,Charch, Encoding e) { if(Ch >255) { foreach(byteBinchE.getbytes (New Char[] {ch}) Buf. ADD (b); } Elsebuf. ADD (byte) ch); } Static intGetInt (byteb) {Charc = (Char) b; if(c >='0'&& C <='9') returnC'0'; if(c >='a'&& C <='F') returnC'a'+Ten; if(c >='A'&& C <='F') returnC'A'+Ten; return-1; } Static intGetChar (stringStrintOffsetintlength) { intval =0; intEnd = length +offset; for(inti = offset; I < end; i++) { Charc =Str[i]; if(C >127) return-1; intCurrent = GetInt ((byte) c); if(Current = =-1) return-1; Val= (Val <<4) +Current ; } returnVal; } Static stringUrlDecode (strings, Encoding e) { if(NULL==s)return NULL; if(S.indexof ('%') == -1&& S.indexof ('+') == -1) returns; if(E = =NULL) e=Encoding.UTF8; LongLen =s.length; varbytes =Newlist<byte>(); intXchar; Charch; for(inti =0; i < Len; i++) Ch=S[i]; if(ch = ='%'&& i +2< Len && S[i +1] !='%') { if(S[i +1] =='u'&& i +5<Len) { //Unicode hex SequenceXchar = GetChar (s, i +2,4); if(Xchar! =-1) {writecharbytes (bytes, (Char) Xchar, E); I+=5; } Elsewritecharbytes (Bytes,'%', E); } Else if(Xchar = GetChar (s, i +1,2)) != -1) {writecharbytes (bytes, (Char) Xchar, E); I+=2; } Else{writecharbytes (bytes,'%', E); } Continue; } if(ch = ='+') writecharbytes (bytes,' ', E); Elsewritecharbytes (Bytes, ch, e); } byte[] buf =bytes. ToArray (); Bytes=NULL; returne.getstring (BUF); }
3. Simple verification
string " Https%3a%2f%2fwww.youtube.com%2fwatch%3fv%3dleghs9mh9xy " ; = urldecode (URL); Console.WriteLine (URL); // Https://www.youtube.com/watch?v=LeghS9MH9xY
C #: UrlDecode ()