John,
I''m sure Aaron Patterson would have a more elegant solution -- he
probably
won''t want to be blamed for this one.
Some Other Aaron
On Thu, Jul 16, 2009 at 12:17 PM, John Norman <john at 7fff.com> wrote:
> Aaron,
>
> As always, THANKS.
>
> John
>
>
> On Thu, Jul 16, 2009 at 3:12 PM, Aaron Starr <astarr at
wiredquote.com>wrote:
>
>> John,
>>
>> I did this in a hacky little script:
>>
>> class JsonForm
>> def initialize(json)
>> @json = json
>> end
>> def page
>> nil
>> end
>> def request_data
>> @json
>> end
>> def enctype
>> ''application/json''
>> end
>> end
>> class WWW::Mechanize
>> def post_json(url, json)
>> post_form(url, JsonForm.new(json))
>> end
>> end
>>
>> Then: web_agent.post_json(''/blah/blah'',
''{"some":"json"}'')
>>
>> If there''s a better way, I''d be interested, too.
>>
>> Aaron
>>
>>
>>
>> On Thu, Jul 16, 2009 at 11:50 AM, John Norman <john at 7fff.com>
wrote:
>> >
>> > I wanted to log this in the feature tracker at rubyforge, but
rubyforge
>> won''t accept my password change. :-( In any case:
>> >
>> > I would like to do a post, but have the body of the post be some
>> arbitrary text (in fact, I''m posting escaped JSON).
>> >
>> > E.g.,
>> >
>> > I want to do something like:
>> >
>> > agent.post_raw(''/ajaxprocessor'', stuff)
>> >
>> > where stuff is a string with value:
>> >
>> >
>>
%7B%22promocode%22%3A%20%22129182%22%2C%20%22zipcode%22%3A%20%22%22%2C%20%22iscobrandselected%22%3A%20false%2C%20%22shippingoptions%22%3A%20%7B%224164011%22%3A%20%22GROUND4164011%22%7D%7D
>> >
>> > To be sure, I could do this with Net::HTTP, but I want to leverage
my
>> existing state in Mechanize (cookies, etc.).
>> >
>> > This doesn''t look like an easy hack in Mechanize, because
it would
>> expect fetch_page to do something different with the params (i.e., no
>> params).
>> >
>> > Any ideas?
>> >
>> > John
>> >
>> >
>> > _______________________________________________
>> > Mechanize-users mailing list
>> > Mechanize-users at rubyforge.org
>> > http://rubyforge.org/mailman/listinfo/mechanize-users
>> _______________________________________________
>> Mechanize-users mailing list
>> Mechanize-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/mechanize-users
>
>
>
> _______________________________________________
> Mechanize-users mailing list
> Mechanize-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mechanize-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/mechanize-users/attachments/20090716/653e60c7/attachment.html>