DownloadFile() Post vs PostData documentation mismatch

Report any Hollywood bugs here
Post Reply
AlexC
Posts: 8
Joined: Sat Mar 09, 2019 2:40 am

DownloadFile() Post vs PostData documentation mismatch

Post by AlexC » Fri Nov 08, 2019 7:26 am

Hi Andreas,

When trying to post some data to my server using the syntax from the Hollywood.guide documentation, e.g.:

Code: Select all

data$, bytes = DownloadFile("http://site.com/script.cgi", Post = "a=1&b=2")
I was getting this error:

1055 Wrong usage/parameters for this command!
Read the documentation! DownloadFile 303

After some trial and error I found that the tag should be named 'PostData'.

p-OS
Posts: 112
Joined: Mon Nov 01, 2010 11:56 pm

Re: DownloadFile() Post vs PostData documentation mismatch

Post by p-OS » Fri Nov 08, 2019 5:55 pm

Code: Select all

data$, bytes = DownloadFile("http://site.com/script.cgi", {Post = "a=1&b=2"})

AlexC
Posts: 8
Joined: Sat Mar 09, 2019 2:40 am

Re: DownloadFile() Post vs PostData documentation mismatch

Post by AlexC » Fri Nov 08, 2019 10:05 pm

Actually that didn't work either, I thought it did because I wasn't getting an error anymore, but it's simply because the 'PostData' tag is ignored.

It looks like depending on what I put in the 'Post' tag the error message changes, so Hollywood is definitely expecting that tag, but the example from the DownloadFile() documentation doesn't work on my end.

AlexC
Posts: 8
Joined: Sat Mar 09, 2019 2:40 am

Re: DownloadFile() Post vs PostData documentation mismatch

Post by AlexC » Fri Nov 08, 2019 11:02 pm

p-OS wrote:
Fri Nov 08, 2019 5:55 pm

Code: Select all

data$, bytes = DownloadFile("http://site.com/script.cgi", {Post = "a=1&b=2"})
I did put the accolades in the script, must have forgotten to write them here.
With {Post = "a=1&b=2"} it just keeps giving me the "Wrong usage/parameters for this command!" error requester.

If I just put {Post} I don't get an error but obviously nothing gets posted
If I put {Post = {"a=1&b=2"}} I get the error 'String expected in table argument "post"!' so it clearly expects a string for the 'Post' tag but somehow doesn't like the DownloadFile("url", {Post="string"}) syntax.

Any idea what could be wrong?

I could fallback to using OpenConnection() and SendData() but I'm not sure how to submit a proper 'POST' request that way.

User avatar
airsoftsoftwair
Posts: 3208
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: DownloadFile() Post vs PostData documentation mismatch

Post by airsoftsoftwair » Sat Nov 09, 2019 12:40 pm

AlexC wrote:
Fri Nov 08, 2019 11:02 pm
Any idea what could be wrong?
The syntax posted by p-OS is definitely the correct way to do it. There's no "PostData" tag, it's called "Post". Please post a minimal test script with a real URL that I can test here...

AlexC
Posts: 8
Joined: Sat Mar 09, 2019 2:40 am

Re: DownloadFile() Post not working

Post by AlexC » Tue Nov 12, 2019 3:47 am

airsoftsoftwair wrote:
Sat Nov 09, 2019 12:40 pm
The syntax posted by p-OS is definitely the correct way to do it. There's no "PostData" tag, it's called "Post". Please post a minimal test script with a real URL that I can test here...
Here's an example using an external server (I was testing with a local server but the outcome is the same as the error happens before the function establishes the connection)

Code: Select all

@DISPLAY {Mode = "Windowed", Height = 500, Width = 500}

data$, bytes = DownloadFile("http://am1ga.com/cgi-bin/myip.cgi", {Post = "a=1"})

Print(data$ .. "\n" .. bytes)
WaitLeftMouse()
Here it gives the error: "Wrong usage/parameters for this command!"

This GET request works:

Code: Select all

data$, bytes = DownloadFile("http://am1ga.com/cgi-bin/myip.cgi")
the CGI script returns my IP

This GET request with key pairs too:

Code: Select all

data$, bytes = DownloadFile("http://am1ga.com/cgi-bin/myip.cgi?a=1&b=2")
the CGI script returns my IP and additional details about the request.

It's only the POST requests which don't work here.

BTW, I'm running Hollywood 8 on OS4.1/A1-XE. I should try on another platform to see if it behaves differently.

The long way around to submit a POST request works:

Code: Select all

  postdata = "a=1&b=2"
  OpenConnection(1, "am1ga.com", 80)
  SendData(1, "POST http://am1ga.com/cgi-bin/myip.cgi HTTP/1.0\r\n" ..
   "Content-Length: " .. StrLen(postdata) .. "\r\n\r\n" ..
   postdata .. "\r\n\r\n")
   data$, bytes, done = ReceiveData(1, #RECEIVEALL)
  CloseConnection(1)
  Print(data$ .. "\n" .. bytes)
but I would like to keep it simpler.

User avatar
airsoftsoftwair
Posts: 3208
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: DownloadFile() Post vs PostData documentation mismatch

Post by airsoftsoftwair » Mon Nov 18, 2019 10:24 pm

Right, looks like the "Post" tag was broken since Hollywood 6.0 and nobody noticed. Fixed now, thanks for reporting!

Code: Select all

- Fix: The "Post" tag in DownloadFile() was broken since Hollywood 6.0

Post Reply