1/*
2 * Rexx/CURL sample program to execute a HTTP POST to a web server.
3 * This example, subscribes the user to the rexxcurl-users mailing
4 * list at SourceForge.
5 * Pass the email address and password on the command line.
6 */
7
8Call RxFuncAdd 'CurlLoadFuncs', 'rexxcurl', 'CurlLoadFuncs'
9Call CurlLoadFuncs
10
11site = 'http://192.168.178.78/bin/response.scgi'
12
13curl = CurlInit()
14If curl \= '' Then
15   Do
16      Call CurlSetopt curl, 'HTTPPOST', 1
17      field.1 = 'tid=0'
18      field.2 = 'id=02'
19      field.3 = 'user=999999'
20      field.4 = 'password=998grfb998'
21      field.0 = 4
22
23      Call CurlSetopt curl, 'VERBOSE', 0
24      Call CurlSetopt curl, 'HTTPPOSTFIELDS', 'field.'
25      Call CurlSetopt curl, 'OUTSTEM', 'response.', x'0D0A'
26
27      Call CurlSetopt curl, 'URL', site
28      If curlerror.intcode \= 0 Then Call Abort 'Error setting URL option'
29
30      Call CurlPerform curl
31      If curlerror.intcode \= 0 Then Call Abort 'Error POSTing to' site
32      /*
33       * Check that the submission worked
34       */
35      Do i = 1 To response.0
36         say response.i
37      End
38      -- try another
39      field.2 = 'id=01'
40      field.5 = 'eta=2303'
41      field.0 = 5
42      Call CurlSetopt curl, 'HTTPPOSTFIELDS', 'field.'
43      Call CurlSetopt curl, 'OUTSTEM', 'response.', x'0D0A'
44      Call CurlPerform curl
45      If curlerror.intcode \= 0 Then Call Abort 'Error POSTing to' site
46      Do i = 1 To response.0
47         say response.i
48      End
49      /*
50       * Cleanup the connection
51       */
52      Call CurlCLeanup curl
53   End
54Call CurlDropFuncs 'UNLOAD'
55Return 0
56
57Abort: Procedure Expose curlerror.
58Parse Arg msg
59Say msg
60If curlerror.curlcode \= 0 Then Say 'cURL error:' curlerror.curlcode '-' curlerror.curlerrm
61Else Say 'RexxCURL error:' curlerror.intcode '-' curlerror.interrm
62Call CurlCLeanup curl
63Call CurlDropFuncs 'UNLOAD'
64Exit 1
65