How to start a Mendix session from another application (to be able to directly download files)

3
For a project we are doing there is the need to download files (pdf's, txt, csv, etc. -files)directly and automated from the server by another (non-mendix app). How to download these is clarified in the answer to a previous question ( https://community.mendix.com/questions/1993/Downloading-file-directly-from-the-application-without-using-the-client). But with the answer a new problem and question arises; how do i enable this other application which has to download these files by their IDs to connect the server, or to put it in other to establish a session? Martijn
asked
4 answers
5

You can simulate a HTTP session from the browser from any scripting language. You should login by POSTing a

{'action':'login','params':{'username':"a",'password':"a", 'locale':'en_US'}}

to <myhost>/xas/

That should return a 200 -ok http status code along with a set-cookie HTTP header. You can use that cookie to post subsequent requests on the runtime, such as a filerequest.

answered
2

I think you could better use web services instead of simulating the client. FTP might also be a good option.

But it may depend on what kind of application this functionality must be implemented in.

answered
1

To establish a session if you know the username and password, you need to POST data to <apphost>/xas in the following format:

{"action":"login","params":{"username":"USERNAME","password":"PASSWORD","locale":""}}

The response to this request will contain two cookies: XASSESSIONID and XASID. Those two cookies need to be added to any subsequent request to the xas / file servlet. How this is done depends entirely on the environment you are working on.

In general, try Google 'YOURLANGUAGE post http data to url' and 'YOURLANGUAGE set/get cookie headers' :)

Note: this is no official api, so it might change in future versions.

answered
0

I think you could better use web services instead of simulating the client. FTP might also be a good option.

But it may depend on what kind of application this functionality must be implemented in.

answered