1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
.TH HGET 1
.SH NAME
hget, hpost, webpaste, urlencode \- retrieve, post to a web page corresponding to a url
.SH SYNOPSIS
.B hget
[
.B -l
|
.B -o
.I file
] [
.B -p
.I body
|
.B -P
] [
.B -r
.I header
] [
.B -m
.I method
] [
.B -b
.I baseurl
] [
.B -v
]
.I url
.PP
.B hpost
[
.B -l
] [
.B -g
.I action
|
.B -p
.I action
|
.B -m
.I action
] [
.B -u
]
.I url
[
.I name:value
|
.I name@file
]
.I ...
.PP
.B webpaste
[
.I file
]
.PP
.B urlencode
[
.B -d
] [
.I file
]
.SH DESCRIPTION
.I Hget
retrieves the web page specified by the URL
.I url
and writes it, absent the
.B -l
and
.B -o
options, to standard output.
.PP
The
.I url
can be a relative path like
.B ../index.html
if a absolute
.I baseurl
was specified with the
.B -b
option.
.PP
If
.I url
is of type HTTP and the
.B -p
or
.B -P
options are specified, then a HTTP POST is performed.
With
.B -p
the data to be posted is provided by the
.I body
argument as a string or alternatively with
.B -P
read from standard input.
.PP
The
.B -l
option causes
.I hget
and
.I hpost
to print the location URL from the transaction response
instead of retrieving the the body data. This is useful
for HTTP POST transactions that redirect to a URL containing
the posted data so we wont refetch the data we just uploaded
to the site.
.PP
The
.B -o
option is used to keep a local file in sync with a
web page. If the web page has been modified later than the
file, it is copied into the file. If the file is up to date
but incomplete,
.I hget
will fetch the missing bytes.
.PP
Option
.B -r
sends an arbitrary HTTP
.IR header .
.PP
Option
.B -m
overrides the HTTP method used for the request.
.PP
Option
.B -v
causes
.I hget
to emit download status on file descriptor 2,
suitable for use with
.I aux/statusbar .
See EXAMPLES.
.PP
.I Hpost
retrieves the web page specified by the URL
.I url,
parses its HTML for form data, then prints
.IR rc (1)
commands to submit the forms with default field
values.
If an
.I action
URL is provided with the
.B -g, -p
or
.B -m
flags, then
.I hget
is invoked to execute the transaction submitting the form data.
.PP
The
.B -g
and
.B -p
flags set the form method to GET and POST, respectively. The
.B -m
flag sets the form method to POST and its enctype to
.B multipart/form-data.
In all cases, the target relative form action URL is set to
.I action.
.PP
The
.B -u
flag sets the target URL to
.I url.
As the
.I url
parameter is always required, the
.B -u
flag can be omitted when
.I url
follows directly after the last option if any.
.PP
The remaining arguments of the form
.B name:value
are interpreted as text form field names and values to be submitted. An
argument of the form
.B name@file
is interpreted as a file upload, with the information following the
.B @
symbol treated as the file name.
For
.B multipart/form-data
uploads (see
.B -m
flag), the file has to be seekable as
.IR file (1)
is invoked to determine its mime type.
.PP
.I Webpaste
uploads the contents either of its standard input or
.I file
to the pastebin website
.B http://okturing.com
and then prints a URL where the contents may be retrieved.
.PP
.I Urlencode
is a helper program to URL encode and decode files. The
.B -d
flag, instead of encode, decodes URL encoded file. If no
.I file
is given, standard input is read. The resulting data
is written to standard output.
.SH EXAMPLES
Download a file from the web.
.IP
.EX
% hget http://9front.org/img/nix-on.jpg >/tmp/nix-on.jpg
.EE
.PP
Use
.I hget
in conjuncton with
.I aux/statusbar
to monitor progress.
.IP
.EX
hget -v -o 9front.iso.bz2 \\
http://www.r-36.net/9front/9front.iso.bz2 \\
|[2] aux/statusbar '9front.iso.bz2'
.EE
.PP
Retrieve the commands needed to submit a form, which may then be
edited and sent.
.IP
.EX
% hpost http://p.intma.in
hpost -u http://p.intma.in -p paste.cgi text:
.EE
.PP
Manually specify fields to be sent to a given
.I url.
.IP
.EX
% hpost -u http://p.intma.in -p paste.cgi text:'test post'
.EE
.PP
Upload a file, print the resulting URL
.IP
.EX
% hpost -l http://i.intma.in file@/tmp/screen.png | rc
.EE
.PP
Upload the output of
.IR ns (1)
to
.B http://okturing.com
.IP
.EX
% ns | webpaste
.EE
.SH SOURCE
.B /rc/bin/hget
.br
.B /rc/bin/hpost
.br
.B /rc/bin/webpaste
.br
.B /sys/src/cmd/urlencode.c
.SH "SEE ALSO"
.IR webfs (4),
.IR ftpfs (4),
.IR file (1)
.SH DIAGNOSTICS
.I Hget ,
.I hpost
and
.I webpaste
require
.IR webfs (4)
service mounted on
.B /mnt/web
to work.
.SH HISTORY
.I Hget
first appeared in Plan 9 from Bell Labs. It was
rewritten as an
.I rc
script for 9front (January, 2012).
.I Hpost
and
.I urlencode
first appeared in 9front (October, 2012).
.I Webpaste
first appeared in 9front (September, 2013).
|