Re: Post Data
Re: Post Data
- Subject: Re: Post Data
- From: Doug McNutt <email@hidden>
- Date: Wed, 2 Jan 2002 19:03:54 -0700
At 11:23 -0800 1/2/02, Brian Johnson wrote:
>
The trick is the URL Access dictionary "form data" item, which you should
>
be able to use as below
>
>
tell application "URL Access Scripting"
>
set x to download "http:/192.168.1.17/" [opt-l]
>
to file "Macintosh Hard Disk:Xmas:reading.txt" [opt-l]
>
form data "command=ch1on&command=saveto1&command=getwave1" [opt-l]
>
replacing yes without progress and unpacking
>
end tell
>
Brian Johnson, Dept of Architecture, University of Washington, Seattle
It works. My thanks to Brian. It does raise a couple of questions though. . .
Here's what Netscape does in response to the html form which comes down from the scope when it is accessed as a simple URL. The form source has a bunch of fill out boxes and results in a POST. (I have removed a bunch of housekeeping stuff and blank lines from the IP sniffer):
Send data (150 bytes).
<0000013D< Content-type: text/plain
<00000157< Content-Disposition: inline; form-data
<00000181< command=select:ch1 on
<00000198< command=save:waveform:fileformat spreadsheet
<000001C6< wfmsend=Get
Receive data (8 bytes).
>
00000000> HTTP/1.1
Receive data (146 bytes).
>
00000049> Content-Type: application/vnd.tek.csv
Receive data (135 bytes).
>
0000009A> -5.51e-06,-2.48 <and 130 kB more>
Here's the AppleScript as I last used it.
set thePost to "command=select:ch2 on"
set thePost to thePost & "&" & "command=save:waveform:fileformat spreadsheet"
set thePost to thePost & "&" & "wfmsend=Get"
set theURL to "
http://192.168.1.17"
set theFile to "Luna:downloads:TEKdata"
tell application "URL Access Scripting"
download theURL form data thePost to file theFile replacing yes without progress and unpacking
end tell
And here's what it does:
Send data (233 bytes).
<00000000< POST / HTTP/1.0
<00000011< Host: 192.168.1.17
<00000025< User-Agent: URL_Access/2.1 (Macintosh; PPC)
<00000052< Content-Type: application/x-www-form-urlencoded
<00000083< Content-Length: 78
<00000099< command=select:ch2 on&command=save:waveform:fileformat
<000000D0< spreadsheet&wfmsend=Get
Receive data (8 bytes).
>
00000000> HTTP/1.1
Receive data (146 bytes).
>
00000049> Content-Type: application/vnd.tek.csv
Receive data (16 bytes).
>
0000009A> -3.2e-07,-0.04 <and 130 kB more>
My followup questions:
What is the "set x to" phrase for on Brian's script? Is it a way to send the download to the bit bucket? It may not have been clear that I really wanted data to be returned and saved.
"downloading" a URL typically means use HTTP to get either a named file or a default called index.html from the server. In this case URL Access sends only a POST request. How does it know to do that? How did I manage to tell it that this request was somehow different from the usual download with some form information appended?
Note that Netscape declares "Content-type: text/plain" and sends each command as a separate line.
URL Access declares "Content-Type: application/x-www-form-urlencoded" but it prevaricates a bit. Note the space in the command "select:ch2 on" which ought to have been changed to a + sign or 2 for URL encoding. I tried putting explicit +s instead of the spaces and everything still worked. Is a user supposed encode form data by hand before calling URL Access? Is that why I have had trouble in the past?
Long ago I gave up on form data in favor of including simple GET style form information in the URL passed to URL Access. Is it true that the form data option is ONLY for forcing URL Access to use the POST method?
The 'scope has the option of downloading the data in pairs of 16 bit bytes rather than ASCII text. It's much faster. Does the "unpacking" option know about things like that? "without progress and unpacking"; does that include unpacking or not? My English teacher would never allow that kind of ambiguity.
Isn't there any way of learning these things without leaning on helpful list members like Brian?
--
--> If you are presented a number as a percentage, and you do not clearly understand the numerator and the denominator involved, you are surely being lied to. <--