The problem of specifying application/x-www-form-urlencoded in the RESTful interface

Source: Internet
Author: User

application/x-www-form-urlencoded Specifies the post data sent, to be URL encoded, but the previous &,= used in front of the post message, as a parameter, it is not necessary to encode, you can skip directly. For example:

Loginusername=admin&loginpassword=admin&param={json message}

The previous two && cannot be encoded, otherwise the Java background does not parse the post data properly. Currently there is a URI in the JSON message:

http://192.168.0.225:8080/kms/services/rest/dataInfoService/downloadFileid=00000001/temp001/097_5848300_10488 &token=7a57a5a7ffffffffc1a0316369671314

There is & in the inside, and if URL encoding is not done, the Java background cannot parse the message properly.

As a result, the previous URL encoding function is simply processed

std::string urlencode (const std::string& STR)

{

std::string strtemp = "";

size_t length = Str.length ();

for (size_t i = 0; i < length; i++)

{

/*

The preceding & is used to differentiate multiple parameter key values, cannot be encoded, and subsequent & must be encoded

*/

if (I < && str[i] = = ' & ')

{

strtemp + = Str[i];

Continue

}

if (Isalnum ((unsigned char) str[i]) | |

(Str[i] = = '-') | |

(Str[i] = = ' _ ') | |

(Str[i] = = '. ') ||

(Str[i] = = ' ~ ') | |

(Str[i] = = '))

strtemp + = Str[i];

else if (str[i] = = ")

strtemp + = "+";

Else

{

strtemp + = '% ';

strtemp + = Tohex ((unsigned char) str[i] >> 4);

strtemp + = Tohex ((unsigned char) str[i]% 16);

}

}

return strtemp;

}


50 is a general figure, and for the moment no other general practice is considered


The problem of specifying application/x-www-form-urlencoded in the RESTful interface

Related Article

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: info-contact@alibabacloud.com 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.