I’m trying to understand the ML support for handling HTTP requests and I’m 
trying to use CURL to test things just to learn. I’m getting an odd behavior 
and I haven’t been able to figure out what I’m doing wrong from either the curl 
info I can find or from the relevant ML docs. 

Here’s my module:

xquery version "1.0-ml";


let $type    := xdmp:get-request-header('Content-Type')
let $field-names := xdmp:get-request-field-names()
return
<response>
<message>This is test remote access</message>
<content-type>{$type}</content-type>
<fields>{
for $name in $field-names
return <field-name>{$name}</field-name>
}</fields>
<request-body>{
for $name in $field-names 
return xdmp:get-request-field($name)}
</request-body>
</response>

I’m trying to use POST to send the data in a file to this module using the 
–data-binary parameter:

curl -X POST  --data-binary "file=@testfile.txt" --user ekimber:ekimber 
http://anglia.corp.mitchellrepair.com:11984/test-remote-access.xqy

However, the response I get is:

<response><message>This is test remote 
access</message><content-type>application/x-www-form-urlencoded</content-type><fields><field-name>file</field-name></fields><request-body>@testfile.txt</request-body></response>

Note that the field value is the string “@testfile.txt”, not the content of the 
file. This is the form of call that appears to be the correct way to associate 
a field name with the data from a file.

If I leave off “file=” then the contents of testfile.txt become the field name:

curl -X POST  --data-binary "@testfile.txt" --user ekimber:ekimber 
http://anglia.corp.mitchellrepair.com:11984/test-remote-access.xqy
<response><message>This is test remote 
access</message><content-type>application/x-www-form-urlencoded</content-type><fields><field-name>This
 is the test
File. More text.
</field-name></fields><request-body/></response>

Which also seems wrong.

I must be doing something wrong, either on the CURL side or on the ML side but 
I can’t figure out what it is. All the examples I could find in the ML docs use 
direct form submission rather than CURL.

Thanks,

Eliot

--
Eliot Kimber
http://contrext.com
 



_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to