I think there's some confusion here. The data you're sending looks like
JSON to me, which in this case is one format you could use to transmit two
key-value pairs.  Percent encoding is an alternative format.

I'd expect the percent-encoded equivalent to look like:
username=third_party_int%40bluefish.com&password=redfish

Whatever you used to construct that json string should be replaced with
some CGI.escape()-using algorithm.

*unless the server is actually expecting to receive a single entity (which
is a json string) -- in which case to be x-www-form-urlencoded you should
prefix the value (the json string) with a form field name, e.g.
"myjsonstring=" + CGI.escape(requestContent)

Cheers,
Matty

Sent from my android
On Sep 22, 2012 3:42 PM, "Jeff Tanner" <lists / ruby-forum.com> wrote:

> Hi
>
> From wikipedia on "percent-encoding":
> http://en.wikipedia.org/wiki/Percent-encoding
>
> "Percent-encoding, also known as URL encoding, ... is also used in the
> preparation of data of the "application/x-www-form-urlencoded" media
> type."
>
> With the following code, do I need to make "requestContent"
> "percent-encoded" by calling "CGI.escape()"?;
>
>     request = Net::HTTP::Post.new(uri.request_uri)
>     request.body = requestContent
>     request["Content-Type"] = "application/x-www-form-urlencoded"
>
> Here is an example of "requestContent" value:
>
> {"username":"third_party_int / bluefish.com","password":"redfish"}
>
> Which when making it "percent-encoded" using "CGI.escape()":
>
> %7B%22username%22%3A%22third_party_int%40bluefish.com
> %22%2C%22password%22%3A%22redfish%22%7D
>
> If I send "requestContent" as is (without making it "percent-encoded")
> to the remote service endpoint expecting "urlencoded", then the service
> request succeeds. However, if I do make "requestContent" to be
> "percent-encoded" by calling "CGI.escape()", then the service request
> fails.
>
> Curious, with the declaration of "request["Content-Type"] =
> "application/x-www-form-urlencoded"", is this making "request.body" to
> be "percent-encoded", and that is why I do not need to assign a
> "percent-encoded" value?
>
> Thanks
>
> - Jeff in Seattle
> If I do not use CGI.escape upon
>
> --
> Posted via http://www.ruby-forum.com/.
>
>