How to include .xml file in cURL POST? (i.e. Why do I get a 415 error?)

1,294 views
Skip to first unread message

adam....@procentive.com

unread,
Aug 2, 2017, 4:07:40 PM8/2/17
to Edge Test Tool (ETT)
I have tomcat running the .war file.  I am able to go to http://localhost:8080/referenceccdaservice/swagger-ui.html and see the page.

I expand the POST on top, enter 'CCDA_IG_Plus_Vocab for validationObjective and 'readme.txt for the referenceFileName as instructed, then I click 'choose file' and upload a .xml file of a ccda that has passed the B1 test previously on the ETT.  When I click 'Try it out' I get back a 200 response code and can see all error counts as 0 in the response body.  Great.

But when I use the curl command I get a 415 error.  

The command listed in the swagger ui is:
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' 'http://localhost:8080/referenceccdaservice/?validationObjective=CCDA_IG_Plus_Vocab&referenceFileName=readme.txt'

I believe I need to change to this to work in my win10 terminal:
curl -X POST --header 'Content-Type:multipart/form-data' --header 'Accept:application/json' "http://adam.internal.procentive.com:8080/referenceccdaservice/?validationObjective=CCDA_IG_Plus_Vocab&referenceFileName=readme.txt"

When I run that command I get back a 415 error, with the description being "The server refused this request because the request entity is in a format not supported by the requested resource for the requested method."

My question is, how do I include the .xml file along with the curl post?  

I tried adding a -d flag followed by the @file name, as that's what it looks like is needed to include some data with the post.  So I first cd'd to where the file is and ran:
curl -i -X POST -d @test.xml --header 'Content-Type:multipart/form-data' --header 'Accept:application/json' "http://adam.internal.procentive.com:8080/referenceccdaservice/?validationObjective=CCDA_IG_Plus_Vocab&referenceFileName=readme.txt"

But that still gave me a 415 error.  What is the right way to include the file in the post?




Jason Countryman

unread,
Aug 2, 2017, 4:35:20 PM8/2/17
to Edge Test Tool (ETT)
Why did you take out the spaces in the headers after the colons?  Just wondering.  I don't use command-line cURL, just the library.

Also, I think you want the -f option, not -d.  Something like:
curl -i -X POST --form ccdaFile=@test.xml --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' "http://adam.internal.procentive.com:8080/referenceccdaservice/?validationObjective=CCDA_IG_Plus_Vocab&referenceFileName=readme.txt"


This is just a guess, really.  Like I said, this is just some googling and familiarity with libcurl.

adam....@procentive.com

unread,
Aug 2, 2017, 5:02:10 PM8/2/17
to Edge Test Tool (ETT)
Ahh.. I did try that --form flag previously with just "curl --form @test.xml ..." but it didn't work.  I guess I didn't know I had to prepend the file with that parameter name like you had in your example.

But once I changed that IT WORKED!

What ended up working for me was:
curl --form  ccdaFile=@test.xml -i -X POST  --header 'Content-Type:multipart/form-data' --header 'Accept:application/json' "http://adam.internal.procentive.com:8080/referenceccdaservice/?validationObjective=CCDA_IG_Plus_Vocab&referenceFileName=readme.txt"

If I leave that space in the header after the colon, I get a curl error saying "curl: (6) Could not resolve host: application".  I am using the terminal on Win10.  Also, I HAVE to wrap the url in double quotes or it doesn't work either, as I get back a 400 error saying that the required string paramer 'referenceFileName' is not preset. .

Thanks Jason... you're my new best CCDA friend  ;)

Jason Countryman

unread,
Aug 3, 2017, 8:10:09 AM8/3/17
to Edge Test Tool (ETT)
Lol, glad I could help.

Mark McDougald

unread,
Aug 15, 2017, 11:08:47 AM8/15/17
to Edge Test Tool (ETT)
Hi Adam, Sorry to bother you for this, but I'm trying to get this tool installed locally and we are having initial problems with the .war file itself.  It doesn't appear to have a web.xml file part of the deploy.  Where do we find this file?  Tomcat is failing to start the app due to this file missing.

Thanks,
Mark




On Wednesday, August 2, 2017 at 4:07:40 PM UTC-4, adam....@procentive.com wrote:

adam....@procentive.com

unread,
Aug 24, 2017, 10:18:51 AM8/24/17
to Edge Test Tool (ETT)
(just got back from vacation.. not sure if you got this figured out or not)

I didn't need a web.xml.  I just put the .war in that tomcat 'webapps' directory, put the referenceccdaservice.xml (from the github page) in the tomcat $CATALINA_BASE/conf/[enginename]/[hostname] directory, then added local files/dirs with vocab files and had the referenceccdaservice.xml point to those files.

Let me know if you have any further questions as I'm in the office.
Reply all
Reply to author
Forward
0 new messages