Hi Eliot, Just my 2 cents: instead of CURL, I use HTTPie <https://httpie.org/>. It is a bit off-topic, but it has been of so much use to me on ML projects, just because they usually use HTTP a their interface.
I can never remember the options of CURL, and its various default values, more oriented towards web pages than REST-like interfaces. The equivalent for HTTPie would look like the following (just to show how easier it it to remember the command-line interface): http POST http://.../ Content-Type:text/plain < testfile.txt Note also that application/text does not exist, you most likely want text/plain. Regards, -- Florent Georges H2O Consulting http://h2o.consulting/ On 23 June 2017 at 16:39, Eliot Kimber wrote: > OK, I think I got it sorted, although I’m not sure I understand why it > needs to be this way. > > On my curl command I added: > > -H "Content-Type: application/text" > > Along with: > > --data-binary "@testfile.txt" > > And then in my XQuery I use: > > xdmp:get-request-body("text") > > And get the response I expected (and wanted). > > Cheers, > > E. > -- > Eliot Kimber > http://contrext.com > > > > > On 6/23/17, 9:18 AM, "general-boun...@developer.marklogic.com on behalf > of Erik Hennum" <general-boun...@developer.marklogic.com on behalf of > erik.hen...@marklogic.com> wrote: > > 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 > > > > _______________________________________________ > 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