lucky me
lucky me

Reputation: 73

HTTP POST request - sending key value pairs - value contains '&'

'&' is used as separator between key and value pairs.

But one of my value contains '&', how can I send this data?

Upvotes: 1

Views: 3309

Answers (1)

Nandana
Nandana

Reputation: 1240

You will have to url encode it (most http related libraries have utility functions for doing so).

For example, key=&value will become key=%26value

You can find more information in Wikipedia.

When a character from the reserved set (a "reserved character") has special meaning (a "reserved purpose") in a certain context, and a URI scheme says that it is necessary to use that character for some other purpose, then the character must be percent-encoded. Percent-encoding a reserved character involves converting the character to its corresponding byte value in ASCII and then representing that value as a pair of hexadecimal digits. The digits, preceded by a percent sign ("%") which is used as an escape character, are then used in the URI in place of the reserved character. (For a non-ASCII character, it is typically converted to its byte sequence in UTF-8, and then each byte value is represented as above.) The reserved character "/", for example, if used in the "path" component of a URI, has the special meaning of being a delimiter between path segments. If, according to a given URI scheme, "/" needs to be in a path segment, then the three characters "%2F" or "%2f" must be used in the segment instead of a raw "/".

This question is probably a duplicate of this.

Upvotes: 2

Related Questions