Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess the HTTP Response from xdmp:http-get()
    primarykey
    data
    text
    <p>Using MarkLogic to pull in data from a web service with <code>xdmp:http-get()</code> or <code>xdmp:http-post()</code>, I'd like to be able to check the headers that come back before I attempt to process the data. In DQ I can do this:</p> <pre><code>let $result := xdmp:http-get($query,$options) (: $query and $options are fine, I promise. :) return $result </code></pre> <p>And the result I get back looks like this:</p> <pre><code>&lt;v:results v:warning="more than one node"&gt; &lt;response&gt; &lt;code&gt;200&lt;/code&gt; &lt;message&gt;OK&lt;/message&gt; &lt;headers&gt; &lt;server&gt;(actual server data was here)&lt;/server&gt; &lt;date&gt;Thu, 07 Jun 2012 16:53:24 GMT&lt;/date&gt; &lt;content-type&gt;application/xml;charset=UTF-8&lt;/content-type&gt; &lt;content-length&gt;2296&lt;/content-length&gt; &lt;connection&gt;close&lt;/connection&gt; &lt;/headers&gt; &lt;/response&gt; </code></pre> <p>followed by the actual response. the problem is that I can't seem to XPath into this response node. If I change my return statement to <code>return $result/response/code</code> I get the empty sequence. If I could check that code to make sure I got a 200 back before attempting to process the actual data that came back it would be much better than using try-catch blocks to see if the data exists and is sane.</p> <p>So, if anyone knows how to access those response codes I would love to see your solution.</p> <p>For the record, I have tried <code>xdmp:get-response-code()</code>, but it doesn't take any parameters, so I don't don't know what response code it's looking at.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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