1. Can I http POST a file
- Posted by ChrisB (moderator) Jan 29, 2013
- 2385 views
Hi
I wish to be able to link my program to my drug suppliers ordering system.
This is an extract from the data interface specs
This is quite a simple system to integrate with as it just requires the client system to POST a simple text file to a URL, and a reply text page is given back as a response. The URL used for posting to is the same for all commands.
The URL is; http://(removed for confidentiality)
Note: Although the system uses the HTTP POST command, you are not able to POST the order via a web page FORM, as the layout of the data is not the same as that generated by a FORM. The POST must be done via an application.
The format of the text file needed to be sent is the same for both ordering and delivery data. It is made up of a header section and a details section. The header section is a list of key/value pairs separated by TAB characters, with the header section terminated by a blank line. The details section is specific to the command being performed;
Example header section;
COMMAND<tab>ORDER
AUTH<tab>YES
USER<tab>JC1
DEL<tab>0
PASSWORD<tab>pass
REFERENCE<tab>000185
CUSTORDERREF<tab>001/000186
TEST<tab>TRUE
<blank_line>
Am I able to do this using euphorias http_post. ie can I post the text file, or do I need to put the key value pairs into the data object.
Chris
2. Re: Can I http POST a file
- Posted by bugmagnet Jan 29, 2013
- 2338 views
Without taking time I don't have right now to test it out, I'd say "Yes". If the receiving end knows that what it's getting is in a format other than key=value pairs, then you should be fine.
Kind regards,
bugmagnet.
3. Re: Can I http POST a file
- Posted by CoJaBo2 Jan 30, 2013
- 2285 views
It doesn't look like theres an option in the HTTP lib to send a raw POST body; there really ought to be.
(Incidentally, wow, drug orders and passwords over HTTP? Are you sure this site is legitimate?)
4. Re: Can I http POST a file
- Posted by ChrisB (moderator) Jan 30, 2013
- 2257 views
Hi
Brought a smile to my face - yes its where I get the antibiotics, anti inflammatories and so on for my patients (I'm a vet).
Chris
5. Re: Can I http POST a file
- Posted by bugmagnet Jan 31, 2013
- 2272 views
It doesn't look like theres an option in the HTTP lib to send a raw POST body
I've just had a look at the docs, and yes, there's no way to specify a custom body.
What you're left with then, is to badger the devs into giving you the option of a custom body, or else write your own http_post function. What platform are you running on? You could either explore the option of wrapping the operating system's library for http transactions (e.g. for Windows), or else wrap something like libcurl.
According to the libcurl site there is support for Euphoria. However, following the links takes you to the site of one Raymond Smith who, it would appear, has given up on Euphoria altogether. He has, however, made his eulibcURL sources available. Some work will need to be done to bring these into line with the most recent version of Euphoria.
Regards,
bugmagnet
6. Re: Can I http POST a file
- Posted by CoJaBo2 Jan 31, 2013
- 2199 views
Hi
Brought a smile to my face - yes its where I get the antibiotics, anti inflammatories and so on for my patients (I'm a vet).
Chris
Well, at least theres no grievous HIPAA violations then lol.. Still, it seems strange they wouldn't bother to secure it; e.g., someone using one of the client apps places an order while on lunch at Starbucks, the guy across the street sniffs the password and orders himself a truckload of ketamine...
Granted, Eu doesn't support HTTPS anyway either...
I created Ticket 842 for the raw POST issue.
7. Re: Can I http POST a file
- Posted by ChrisB (moderator) Jan 31, 2013
- 2195 views
Hi
Thanks.
Yes, but it would end up being delivered to the practice that ordered it, not some random dealers cafe!
Cheers
Chris
8. Re: Can I http POST a file
- Posted by m_sabal Feb 01, 2013
- 2183 views
Kat had submitted code for EuNet that supported this functionality. I never used it myself, so it took me a little time to verify that it would actually work. The procedure eunet_set_sendheader, along with some supporting routines, allows you to specify POSTDATA in any format you choose.
9. Re: Can I http POST a file
- Posted by useless_ Feb 01, 2013
- 2163 views
Kat had submitted code for EuNet that supported this functionality. I never used it myself, so it took me a little time to verify that it would actually work. The procedure eunet_set_sendheader, along with some supporting routines, allows you to specify POSTDATA in any format you choose.
I can't use Euphoria now. Euphoria-4.0.5-Jan30-2013 still has the match-replace memory leak which crashes the programs, and Euphoria-4.1.0-29-Jan-2013 just starts up and dies without doing anything.
useless
10. Re: Can I http POST a file
- Posted by mattlewis (admin) Feb 01, 2013
- 2128 views
I can't use Euphoria now. Euphoria-4.0.5-Jan30-2013 still has the match-replace memory leak which crashes the programs, and Euphoria-4.1.0-29-Jan-2013 just starts up and dies without doing anything.
It looks like a conflict due to a custom makefile was preventing the eubins from properly updating. This should be fixed now.
Matt
11. Re: Can I http POST a file
- Posted by SDPringle Feb 03, 2013
- 2064 views
The original poster should look at the section on MULTIPART_FORM_DATA in the manual. I think this is what the original poster needs. He can use this with http_post.
12. Re: Can I http POST a file
- Posted by CoJaBo2 Feb 03, 2013
- 2016 views
The original poster should look at the section on MULTIPART_FORM_DATA in the manual. I think this is what the original poster needs. He can use this with http_post.
The application (i think, the way its described) uses a custom POST format. This is not supported by http_post which only supports multipart and URL-encoded, nothing else.
13. Re: Can I http POST a file
- Posted by m_sabal Feb 04, 2013
- 1984 views
Just curious, how would Eu4's http implementation handle POSTing an XML file over HTTP, a common request in SaaS?
14. Re: Can I http POST a file
- Posted by ChrisB (moderator) Feb 04, 2013
- 1982 views
Hi
Exactly the same way as I want it I would imagine.
I'm still waiting my test login from the drug company, but curl looks like the way forward so far - the command line curl being the simpler to use ( curl -d "filename=@filename" url ), then I'll look at euLibCurl once thats running.
Chris
15. Re: Can I http POST a file
- Posted by useless_ Feb 04, 2013
- 1919 views
Hi
Exactly the same way as I want it I would imagine.
I'm still waiting my test login from the drug company, but curl looks like the way forward so far - the command line curl being the simpler to use ( curl -d "filename=@filename" url ), then I'll look at euLibCurl once thats running.
Chris
As you wish, but what i contributed to eunet was so i could upload data files however i liked. I simply did not care how it was expected in html handlers. I used this to remotely, in a hidden fashion, put Tiggr on the web.
useless
16. Re: Can I http POST a file
- Posted by ChrisB (moderator) Feb 05, 2013
- 1887 views
Hi Kathy
Ok, so what would be the bare minimum program required to send (or POST) foo.txt to http://url?
Cheers
Chris
17. Re: Can I http POST a file
- Posted by gbonvehi Feb 05, 2013
- 1896 views
Hi
Exactly the same way as I want it I would imagine.
I'm still waiting my test login from the drug company, but curl looks like the way forward so far - the command line curl being the simpler to use ( curl -d "filename=@filename" url ), then I'll look at euLibCurl once thats running.
Chris
According to curl's man page
-d/--data <data> (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the con‐ tent-type application/x-www-form-urlencoded. Compare to -F/--form. -d/--data is the same as --data-ascii. To post data purely binary, you should instead use the --data-binary option. To URL-encode the value of a form field you may use --data-urlen‐ code. If any of these options is used more than once on the same command line, the data pieces specified will be merged together with a separating &-symbol. Thus, using '-d name=daniel -d skill=lousy' would generate a post chunk that looks like 'name=daniel&skill=lousy'. If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. The contents of the file must already be URL-encoded. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar.
So, untested and taken from Eu4's docs, the following should work:
include std/net/http.e include std/io.e sequence inputfile = "YOURFILE" sequence data sequence file_content file_content = read_file(inputfile, BINARY_MODE) -- According to net.e source, if sequence(data[1]) then contet type is urlencoded data = { { "filename", file_content, inputfile, "text/plain", ENCODE_BASE64 } } -- You may try ENCODE_NONE here object result = http_post("http://example.com", data) if atom(result) then printf(1, "Web error: %d\n", result) abort(1) end if
Regards,
Guillermo
Edit: I've just realized that -d "filename=@filename" doesn't include the file contents, I thought it did, I went ahead and tested without filename= part and that includes the content but it seems to concatenate lines without EOL separators which I guess is not the desired input.
To achieve a similar POST request (this is correctly splitted with EOL chars in Eu4 simply change
data = { { "filename", file_content, inputfile, "text/plain", ENCODE_BASE64 } } -- You may try ENCODE_NONE here
data = file_content
Edit2: Should've been BINARY_MODE
18. Re: Can I http POST a file
- Posted by ChrisB (moderator) Feb 05, 2013
- 1853 views
Hi
Thanks. That looks good. As I said, as soon as I've got a test login, I'll give these a go, and report back.
Chris
19. Re: Can I http POST a file
- Posted by gbonvehi Feb 05, 2013
- 1867 views
I'm glad to help, you may want to try using url:encode(data) before sending it too to convert non printable chars to their hex escaped value (%09, %20, etc).
If you cannot get it to work with Euphoria but with something else like Curl, you could watch what it's being sent to the server using Fiddler or Wireshark and post it here (without confidential data of course) so we can spot what changes may be required to satisfy your requirement.
Cheers,
Guillermo