This code gets a brazilian postal code and query the "Correios" webservice site for the actual street address. The result is given in XML.
#!/usr/bin/perl use HTTP::Request; use LWP::UserAgent; my $CEP = shift || "91751-000"; my $content =<<"HERE"; <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" x +mlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Query xmlns="urn:Microsoft.Search"> <queryXml> <![CDATA[ <QueryPacket xmlns='urn:Microsoft.Search.Query' revision='1' build='(1 +1.0.5329)'> <Query domain='{1698075D-E2F5-4254-87B2-7FC9E9AB0780}'> <QueryId>{AE4CDA59-C3EC-496A-B0B3-B21A55EEA0CC}</QueryId> <OriginatorId>{F6FF7BE0-F39C-4ddc-A7D0-09A4C6C647A5}</OriginatorId +> <SupportedFormats> <Format revision='1'> urn:Microsoft.Search.Response.Document:Document</Format> <Format revision='1'> urn:Microsoft.Search.Response.Content:Content</Format> <Format revision='1'> urn:Microsoft.Search.Response.Form:Form</Format> </SupportedFormats><Context> <QueryText type='STRING' language='en-us' >$CEP</QueryText> <LanguagePreference>en-us</LanguagePreference> <Requery></Requery></Context> <Range id='result'></Range> <OfficeContext xmlns='urn:Microsoft.Search.Query.Office.Context' revision='1'> <UserPreferences> <ParentalControl>false</ParentalControl> </UserPreferences> <ServiceData></ServiceData> <ApplicationContext> <Name>Microsoft Office Word</Name> <Version>(11.0.5329)</Version> <SystemInformation> <SkuLanguage>en-us</SkuLanguage> <LanguagePack>en-us</LanguagePack> <InterfaceLanguage>en-us</InterfaceLanguage> <Location>US</Location> </SystemInformation> </ApplicationContext> <QueryLanguage>en-us</QueryLanguage> <KeyboardLanguage>en-us</KeyboardLanguage> </OfficeContext> <Keywords xmlns='urn:Microsoft.Search.Query.Office.Keywords' revision='1'> <QueryText>food</QueryText> <Keyword><Word>food</Word></Keyword> </Keywords> </Query> </QueryPacket> ]]> </queryXml> </Query> </soap:Body> </soap:Envelope> HERE my $ua = LWP::UserAgent->new(); my $request = HTTP::Request->new( POST => 'http://consultacep.correios.com.br/office2003/Query.asmx' + ); $request->header( 'SOAPAction' => "urn:Microsoft.Search/Query" ); $request->header( 'Content-Type' => "text/xml; charset=utf-8" ); $request->content( $content ); print $request->as_string; my $response = $ua->request( $request ); print $response->as_string;

In reply to Querying brazilian CEP (postal code) webservices by fglock

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.