Hi Will,
I'm surprised that url-encode and encode-for-uri are different; maybe
somebody more knowledgeable can explain that one. All things equal, I'd
prefer the w3c function that you found.
I'm assuming that 401 is a bit closer to the solution, not a different
error -- are you missing a method attribute on http:authentication? The
default REST server requires method="digest"
Charles
On 02/21/2013 01:19 PM, Will Thompson wrote:
After some testing, it appears that xdmp:http-get doesn't like
xdmp:xdmp:url-encode output, but it's okay with fn:encode-for-uri. The call is
to a self-signed SSL appserver. This works:
let $rest-url :=
concat($url,
'v1/values/uris?options=uris&format=xml&structuredQuery=',
fn:encode-for-uri(xdmp:quote($q)))
return
xdmp:http-get($url,
<options xmlns="xdmp:document-get" xmlns:http="xdmp:http">{
element http:authentication {
element http:username { 'user' },
element http:password { 'pass' }
} }
<http:verify-cert>false</http:verify-cert>
</options>)
But swapping fn:encode-for-uri for xdmp:url-encode results in a 401 error:
<response xmlns="xdmp:http">
<code>401</code>
<message>Unauthorized</message>
<headers>
<www-authenticate>Digest realm="public", qop="auth",
nonce="c975aeaf1b6774e1a51f5b30d9ca7c61",
opaque="a08df0deda23d70d"</www-authenticate>
<content-type>application/xml</content-type>
<server>MarkLogic</server>
<content-length>211</content-length>
<connection>close</connection>
</headers>
</response>
<rapi:error xmlns:rapi="http://marklogic.com/rest-api">
<rapi:status-code>401</rapi:status-code>
<rapi:status>Failed Auth</rapi:status>
<rapi:message-code/>
<rapi:message>Unauthenticated</rapi:message>
</rapi:error>
I tested saving the output of both functions to a local file and using those
strings to hit the endpoint from a browser, and they both worked. Is this a bug
or something I likely don't understand about http-get and/or url-encode?
-Will
From: Charles Greer <[email protected] <mailto:[email protected]>>
Organization: MarkLogic Corporation
Reply-To: MarkLogic Discussion <[email protected]
<mailto:[email protected]>>
Date: Wednesday, February 20, 2013 4:24 PM
To: MarkLogic Discussion <[email protected]
<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Dynamically building a structured query
Hi Will,
What's wrong with double quotes?
Are you looking to encode the whole shebang? How about
concat($url,
$path,
"?options=uris&structuredQuery=",
xdmp:url-encode(xdmp:quote($structured-query-xml)))
Charles
On 02/20/2013 04:06 PM, Will Thompson wrote:
> This is kind of a pedantic style-related question, but I am building a
> structured query and want to submit it to the REST values endpoint. However,
> that endpoint doesn't like double quotes, so I can't do something tidy like:
> concat($url, $path, "?options=uris&structuredQuery=",
> xdmp:quote($structured-query-xml)) because xdmp:quote outputs double quotes
for
> the namespace declaration. I tried POSTing the XML, but the values endpoint
only
> accepts GET requests (?). I couldn't find an option to force xdmp:quote to
> serialize attributes using single quotes (maybe that's not technically
allowed?).
>
> Is there a better way to approach this, or is my best option to just replace
the
> double quotes from xdmp:quote output?
>
> -Will
>
>
>
>
> _______________________________________________
> General mailing list
>
[email protected]http://developer.marklogic.com/mailman/listinfo/general
--
Charles Greer
Senior Engineer
MarkLogic Corporation
[email protected]
Phone: +1 707 408 3277
www.marklogic.com
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
--
Charles Greer
Senior Engineer
MarkLogic Corporation
[email protected]
Phone: +1 707 408 3277
www.marklogic.com
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general