Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Querying brazilian CEP (postal code) webservices

by fglock (Vicar)
on Mar 08, 2005 at 22:20 UTC ( [id://437742]=CUFP: print w/replies, xml ) Need Help??

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;

Replies are listed 'Best First'.
Re: Querying brazilian CEP (postal code) webservices
by Anonymous Monk on Jan 03, 2006 at 18:41 UTC
    It works smoothly, it pretends to be MS Office, whhen querying

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://437742]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2024-03-19 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found