I'm not sure how to change the Content-Type header with HTTP::Request::Common (for plain WWW::Mechanize), but it should give you at least a HTTP::Request whose Content-Type you can change later on:

use strict; use HTTP::Request::Common; my $request= POST 'http://book.flypeach.com/WebService/B2cService.asmx +/SearchLowFareSingleMonth', Content_Type => 'application/json', Content => '{"strFromAirport":"KIX","strToAirport":"HKG","dep +artMonth":"20150606","returnMonth":"20150606","iOneWay":"true","iAdul +t":2,"iChild":0,"iInfant":0,"BoardingClass":"","CurrencyCode":"JPY"," +strPromoCode":"","SearchType":"FARE","iOther":0,"otherType":"","stIpA +ddress":"","strCurrentDate":"20150406"}', ; print $request->as_string; __END__ POST http://book.flypeach.com/WebService/B2cService.asmx/SearchLowFare +SingleMont h Content-Length: 295 Content-Type: application/json {"strFromAirport":"KIX","strToAirport":"HKG","departMonth":"20150606", +"returnMonth":"20150606","iOneWay":"true","iAdult":2,"iChild":0,"iInf +ant":0,"BoardingClass":"","CurrencyCode":"JPY","strPromoCode":"","Sea +rchType":"FARE","iOther":0,"otherType":"","stpAddress":"","strCurrent +Date":"20150406"}

If you want to keep using WWW::Mechanize::Firefox, note that its support to add custom headers is somewhat limited, but the same approach could still work. But if you already use WWW::Mechanize::Firefox, why not just keep automating the complete website and programmatically click your way to the data you want?


In reply to Re: Web page scraping from AJAX page with POST JSON data by Corion
in thread Web page scraping from AJAX page with POST JSON data by ronstudio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.