Httputility.urlencode encoding Rewrite

Source: Internet
Author: User
Tags urlencode

1. Some system methods, such as. NET System method Httputility.urlencode ' = ' is encoded as '%3d ' instead of%3d, causing the cryptographic signature to pass through validation, please check with the developer.

In 2.Java 1.3 and earlier versions, some special characters were not encoded, such as asterisks (*), when the method under was called for URL encoding. because the asterisk (*) must be encoded in the URL encoding rule, if the above method is used in the request string with an asterisk (*), the resulting signature cannot be validated. For example, when calling the V3/pay/buy_goods interface, the Payitem parameter value must contain *, after encoding using the method under Class, the developer will manually replace the asterisk character "*" with "%2a". failure to do so will cause the cryptographic signature to pass through validation, and the developer should be aware of the check.

3. The UrlEncode method in some languages encodes "space" as "+" and should actually be encoded as "%2b". This will also generate the wrong signature, causing the signature to pass through validation. Please check with the developer to manually replace "+" with "%2b". In PHP, URL encoding is recommended using the Rawurlencode method.

The following is an urlencode rewrite about the C # language:

        /// <summary>        ///urlencode rewrite: lowercase to uppercase, special word traits classes/// </summary>        /// <param name= "STRSRC" >Original String</param>        /// <param name= "encoding" >Encoding Method</param>        /// <param name= "Btoupper" >whether to turn uppercase</param>        /// <returns></returns>        Private stringUrlEncode (stringSTRSRC, System.Text.Encoding Encoding,BOOLbtoupper) {System.Text.StringBuilder StringBuilder=NewSystem.Text.StringBuilder ();  for(inti =0; i < strsrc.length; i++)            {                stringt =Strsrc[i].                ToString (); stringK =Httputility.urlencode (t, encoding); if(T = =k) {stringbuilder.append (t); }                Else                {                    if(Btoupper) stringbuilder.append (K.toupper ()); ElseStringbuilder.append (k); }            }            returnStringbuilder.tostring (). Replace ("+","%2b"); }
Call Method:
string org_loc = this. UrlEncode ("/dfdasf/get_api_m", Encoding.UTF8, True);

Httputility.urlencode encoding Rewrite

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.