one of my customers asked for a simple webservice that is able to receive an XML file and store it in database or folder structure.
I studied one of the Youtube Xojo examples but that listens to specific call to deliver info fetched out of a database.
The things I want is:
listen to a specific port
if a request comes in receive the file
notify the sender
store the file.
How to accomplish this?
I would be happy if someone can put me in that direction.
Here’s an example request that you can use to test it:
[code]## POST Example Duplicate
curl -X “POST” “http://127.0.0.1:8080/” \
-H ‘Content-Type: text/plain; charset=utf-8’ \
-d $’<?xml version="1.0" encoding="UTF-8"?>
The World
Tim Dietrich
Xojo
Xojo rocks!
'[/code]
The app:
Listens on port 8080 by default. You can adjust this using the Server’s Port property (in the App.Run event handler).
Stores the body of an HTTP POST request in the app’s directory. The files generated are named like this - 20190214-135328-127.0.0.1.xml - but you can change this to meet your requirements.
Responds with “OK” and an HTTP status code of 200.
A couple of comments:
You will probably want to authenticate the requests. For ideas on how to do this, see: https://forum.xojo.com/52456-aloe-express-authentication-options
You might want to evaluate the payload to ensure that it is a well-formed XML file.
And you might also want to look at the request “Content-Type” header to ensure that the payload is supposed to be an XML file.
Let me know if you have any questions - and best of luck with your project!
Works like a charm. It checks the readability of the data, and now I’m looking into the well-formedness of the XML file.
I noticed it is very fast. Thanks again.