Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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;

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found