Rob,You're right!
I installed Visual Sniffer for monitor http traffic:

Before urlencoding my post json data,I got wrong data:

?POST /addressbook/save HTTP/1.1?POST /addressbook/save HTTP/1.1
Accept: text/javascript, text/html, application/xml, text/xml, */*
Accept-Language: zh-cn
x-prototype-version: 1.5.0_pre1
Referer: http://202.127.166.89/docs/addressbook.html
x-requested-with: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
Host: 202.127.166.89
Content-Length: 55
Connection: Keep-Alive
Cache-Control: no-cache

json={"city":"���浜�","street":"1","zip":"1","tel":"1"}


After urlencoding my post json data,this is correct:

?POST /addressbook/save HTTP/1.1?POST /addressbook/save HTTP/1.1
Accept: text/javascript, text/html, application/xml, text/xml, */*
Accept-Language: zh-cn
x-prototype-version: 1.5.0_pre1
Referer: http://202.127.166.89/docs/addressbook.html
x-requested-with: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
Host: 202.127.166.89
Content-Length: 114
Connection: Keep-Alive
Cache-Control: no-cache

json=%7B%22city%22%3A%22%E5%8C%97%E4%BA%AC%22%2C%22street%22%3A%22%22%2C%22zip%22%3A%22%22%2C%22tel%22%3A%22%22%7D

I used prototype1.5 and json2 in client,but I hadn't urlencoded post
data when post xml data.
But whenI posted json data with plaintext format,I got wrong.
I think browser should urlencode xml data,but don't do that for
plaintext just like my json post data.

On Jan 28, 2008 9:28 PM, Rob Heittman <[EMAIL PROTECTED]> wrote:
>
> The modified classes attached appear to work correctly.
>
> The problem is that form data in the entity is expected to be "url encoded"
> -- that is, transformed to sequences like %2F instead of / -- the example
> you provided skips this step.  By using the Form abstraction on both sides
> (or just ensuring the client properly url-encodes the data) you will get the
> correct results.  All browsers I know of will url-encode a POSTed form
> submission.
>
> So the client pattern looks like this:
>
>         final Form form = new Form();
>
> form.add("json","{\"zip\":1,\"tel\":\"1\",\"street\":\"1\",\"city\":\"北京\"}");
>          Representation jsonRepr =
> form.getWebRepresentation(CharacterSet.UTF_8);
>         request.setEntity(jsonRepr);
>
> The data enroute looks like this:
>
> json=%7B%22zip%22%3A1%2C%22tel%22%3A%221 ... etc.
>
> ... and it comes back correctly from the (unmodified) server.
>
> I think the difference between the example I constructed earlier and your
> JSON use case is that the browser automatically does this step, but your
> JSON client skipped it.
>
> - R
>
>
>
>
> On 1/27/08, cleverpig <[EMAIL PROTECTED]> wrote:
> > Great!
> > But now,Rob,do you have time to take a look?
> >
> > On Jan 25, 2008 12:56 PM, Rob Heittman <[EMAIL PROTECTED]> wrote:
> > > Thanks for this continued diligence ... I am travelling right now, but
> will
> > > have a look at it Friday morning (US Central time) - that is, about 8
> hrs
> > > from now.
> > >
> > >
> > > On 1/24/08, cleverpig <[EMAIL PROTECTED]> wrote:
> > > > Hi,Rob.I made a pair of test program that can prove my
> consideration,pls
> > > try on:
> > > >
> > > >
> > >
> >
> >
> >
> > --
> > cleverpig
> > Location: Beijing
> > Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
> > Zipcode: 100031
> > Phone: 010-66415588-1113
> > MSN: [EMAIL PROTECTED]
> > QQ: 149291732
> > Skepe: cleverpigatmatrix
> > My Facebook ID:cleverpig
> > My Blog: hihere.sohu.com
> > My Tags: del.icio.us/cleverpig
> > My Twitter: twitter.com/cleverpig
> > My Organization: www.beijing-open-party.org
> > 一些值得关注的唧歪:
> >   http://jiwai.de/t/jmatrix/
> >   http://jiwai.de/t/db4o/
> >   http://jiwai.de/t/matrix-community/
> >
>
>



-- 
cleverpig
Location: Beijing
Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
Zipcode: 100031
Phone: 010-66415588-1113
MSN: [EMAIL PROTECTED]
QQ: 149291732
Skepe: cleverpigatmatrix
My Facebook ID:cleverpig
My Blog: hihere.sohu.com
My Tags: del.icio.us/cleverpig
My Twitter: twitter.com/cleverpig
My Organization: www.beijing-open-party.org
一些值得关注的唧歪:
  http://jiwai.de/t/jmatrix/
  http://jiwai.de/t/db4o/
  http://jiwai.de/t/matrix-community/

Reply via email to