Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with XML and HTTParty
    primarykey
    data
    text
    <p>I've just started using HTTParty, and i've encountered a problem in the way it builds the Hash from the XML replied by the server.</p> <p>If i setup the following Builder template on the server:</p> <pre><code>xml.thunt :sendSubscriptionResult, :"xmlns:thunt" =&gt; "http://example.com/thunt", :status =&gt; @status </code></pre> <p>everything works well, i.e. the Hash built by HTTParty matches the XML generated by Builder, (the latter can be observed by making the same request via curl):</p> <p><strong>curl Request</strong></p> <pre><code>curl -s -H "Accept: text/xml" -d "xml=`cat vendor/testxml/requests/sendsubscription.xml`" $SERVER/${name} </code></pre> <p><strong>Reply as seen by curl</strong></p> <pre><code> '&lt;thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed" /&gt;' </code></pre> <p><strong>HTTParty request</strong></p> <pre><code>TreasureHunt.post('/sendsubscription', :query =&gt; { :xml =&gt; sub } ) </code></pre> <p><strong>Reply in HTTParty</strong></p> <pre><code>{"thunt:sendSubscriptionResult"=&gt;{"status"=&gt;"alreadySubscribed", "xmlns:thunt"=&gt;"http://example.com/thunt"}} </code></pre> <hr> <p><strong>But</strong>, if in the Builder i specify that i want the sendSubscriptionResult element to have a text node:</p> <pre><code>xml.thunt :sendSubscriptionResult, "Hello, World", :"xmlns:thunt" =&gt; "http://example.com/thunt", :status =&gt; @status </code></pre> <p>(note the "Hello, World" addition) the two tools suddenly disagree.</p> <p><strong>curl</strong></p> <pre><code>'&lt;thunt:sendSubscriptionResult xmlns:thunt="http://example.com/thunt" status="alreadySubscribed"&gt;Hello, World&lt;/thunt:sendSubscriptionResult&gt;' </code></pre> <p><strong>HTTParty</strong></p> <pre><code>{"thunt:sendSubscriptionResult"=&gt;"Hello, World"} </code></pre> <p>As you can see, HTTParty has stripped all of the element's attributes, and has put only the text node in the resulting Hash</p> <p>Is this a bug in HTTParty or am I doing something wrong? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload