On 10 August 2015 at 21:56, Nick Sincaglia wrote:
Hi,
> We have OAuth2 working with the refresh and access tokens. We know
> that works.
The first thing you need to know here, is the sequence of HTTP
requests and responses flowing around. The HTTP Client is a low-level
API, not providing you with any OAuth mechanism, for instance.
> We are not sure about some of our settings. In particular, we are
> not sure if our media-type setting is right in this tag:
> <http:multipart media-type="multipart/mixed" boundary="xyzBouNDarYxyz”>
It is... if you want to send a multipart/mixed request, with the given
boundary. I don't know the Box API, but the element looks correct to
me.
> Or if our name/value attributes are correct in this tag:
> <http:header name="content-disposition" value="attributes”/>
That will generate a HTTP header like: "content-disposition:
attributes". Actually, because it is in a multipart request,
technically it is not a HTTP header, it is part of the request entity
body, which itself is a sequence of pseudo-headers + body content
pairs. That is how multipart works:
```
Content-Type: multipart/alternative; boundary=xyzBouNDarYxyz
X-Comment: real headers
--xyzBouNDarYxyz
Content-Type: text/plain
X-Comment: pseudo-headers part #1
Hello, world!
--xyzBouNDarYxyz
Content-Type: application/xml
X-Comment: pseudo-headers part #2
<hello>World!</hello>
--xyzBouNDarYxyz--
```
This request can be represented by:
```
<http:request>
<http:header name="X-Comment" value="real headers"/>
<http:multipart media-type="multipart/alternative" boundary="xyzBouNDarYxyz">
<http:header name="X-Comment" value="pseudo-headers part #1"/>
<http:body media-type="text/plain">Hello, world!</http:body>
<http:header name="X-Comment" value="pseudo-headers part #2"/>
<http:body media-type="application/xml">
<hello>World!</hello>
</http:body>
</http:multipart>
</http:request>
```
As you can see, there is a positional grouping within http:multipart:
the pseudo-headers apply to the next body in the sequence.
> I think <http:body media-type="image/png">{$content}</http:body> is
> correct but we are not entirely sure.
That's an interesting question, as it involves binary data. I am not
sure what the eXist function util:binary-doc() returns, and how it
gets added to the element. What I do with binary (and usually with
body content in general, unless it is static in the request) is to use
the 3d parameter of http:send-request(), namely $bodies. The query:
http:send-request(
<http:request href="...">
<http:body media-type="plain/text">Hello, world!</http:body>
</http:request>)
is the same as:
http:send-request(
<http:request href="...">
<http:body media-type="plain/text"/>
</http:request>,
(),
'Hello, world!')
That is, http:body may serve only as a placeholder for its attributes
values, the content itself being passed as an extra parameter. In
case of a multipart request with, say, 2 http:body elements, you pass
a sequence of 2 items for the parameter. With the above multipart
sequence, if you remove the content of the http:body elements, you can
have instead (showing only the relevant bits):
http:send-request(
<http:request href="...">
<http:multipart media-type="...">
<http:body media-type="plain/text"/>
<http:body media-type="application/xml"/>
</http:multipart>
</http:request>,
(),
('Hello, world!', <hello>World!</hello>))
If util:binary-doc() returns either a xs:hexBinary or a
xs:base64Binary, then you can pass it in the 3 parameter then.
If that does not help you, you will need to describe exactly the HTTP
request you want to send, if you want us to double-check you got the
syntax right. Here I am half guessing, half describing how it works
in general. But that should (hopefully) give you the keys for what
you're trying to do.