From: Matthew Kerwin Date: 2012-09-23T11:15:08+09:00 Subject: Re: "percent-encoding" and "application/x-www-form-urlencoded" --14dae93407cfa6a4f204ca550acb Content-Type: text/plain; charset=ISO-8859-1 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" 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/. > > --14dae93407cfa6a4f204ca550acb Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

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

I'd expect the percent-encoded equivalent to look like: username=3Dt= hird_party_int%40bluefish.com&pas= sword=3Dredfish

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 (whi= ch is a json string) -- in which case to be x-www-form-urlencoded you shoul= d prefix the value (the json string) with a form field name, e.g. "myj= sonstring=3D" + CGI.escape(requestContent)

Cheers,
Matty

Sent from my android

On Sep 22, 2012 3:42 PM, "Jeff Tanner"= <lists@ruby-forum.com> w= rote:
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" me= dia
type."

With the following code, do I need to make "requestContent"
"percent-encoded" by calling "CGI.escape()"?;

=A0 =A0 request =3D Net::HTTP::Post.new(uri.request_uri)
=A0 =A0 request.body =3D requestContent
=A0 =A0 request["Content-Type"] =3D "application/x-www-form-= urlencoded"

Here is an example of "requestContent" value:

{"username":"third_party_int@bluefish.com","password":"redfish&= quot;}

Which when making it "percent-encoded" using "CGI.escape()&q= uot;:

%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 s= ervice
request succeeds. However, if I do make "requestContent" to be "percent-encoded" by calling "CGI.escape()", then the s= ervice request
fails.

Curious, with the declaration of "request["Content-Type"] = =3D
"application/x-www-form-urlencoded"", is this making "r= equest.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/.

--14dae93407cfa6a4f204ca550acb--