Hi, Eliot: Try specifying the content-type.
I believe that, if a POST request doesn't specify the content-type, curl defaults the content-type to application/x-www-form-urlencoded (This convenience may or may not be seen as a feature.) Regards, Erik Hennum ________________________________________ From: general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.com] on behalf of Eliot Kimber [ekim...@contrext.com] Sent: Thursday, June 22, 2017 3:02 PM To: MarkLogic Developer Discussion Subject: [MarkLogic Dev General] Using CURL to Test ML HTTP Processing 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 _______________________________________________ General mailing list General@developer.marklogic.com Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general