-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartPage.aspx.vr
More file actions
212 lines (164 loc) · 7.17 KB
/
StartPage.aspx.vr
File metadata and controls
212 lines (164 loc) · 7.17 KB
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
Using System
Using System.Web
Using System.Net
Using System.IO
Using System.Text
Using System.Collections.Specialized
Using SYstem.Collections.Generic
BegClass StartPage Partial(*Yes) Access(*Public) Extends(System.Web.UI.Page)
BegEnum HttpVerb
DclEnumFld POST
DclEnumFld GET
EndEnum
BegSr InitiateSubmitPostRequest Access(*Private) +
Event(*This.buttonSubmitPostRequest.Click)
DclSrParm sender Type(*Object)
DclSrParm e Type(System.EventArgs)
DclFld SubmitData Type(NameValueCollection)
DclFld DataReceived Type(NameValueCollection)
SubmitData = CollectSubmitData()
// With POST verb, data is passed as an internal part of
// the request body.
DataReceived = SubmitRequest(HttpVerb.POST, 'TestTarget.aspx', SubmitData)
ShowDataReceived(DataReceived)
EndSr
BegSr InitiateSubmitGetRequest Access(*Private) +
Event(*This.buttonSubmitGetRequest.Click)
DclSrParm sender Type(*Object)
DclSrParm e Type(System.EventArgs)
DclFld SubmitData Type(NameValueCollection)
DclFld DataReceived Type(NameValueCollection)
SubmitData = CollectSubmitData()
// With GET verb, data is passed as a query string.
DataReceived = SubmitRequest(HttpVerb.GET, 'TestTarget.aspx', SubmitData)
ShowDataReceived(DataReceived)
EndSr
BegFunc SubmitRequest Type(NameValueCollection)
DclSrParm RequestType Type(HttpVerb)
DclSrParm ASPXPage Type(*String)
DclSrParm SubmitData Type(NameValueCollection)
DclFld url Type(*String)
DclFld encodedData Type(*String)
DclFld responseString Type(*String)
DclFld dataReceived Type(NameValueCollection)
url = GetUrlWithPort(ASPXPage)
// Convert your input values to a query string.
encodedData = EncodeData(SubmitData)
// responseString is the server response.
If RequestType = HTTPVerb.POST
responseString = SubmitPostRequest(url, encodedData)
Else
responseString = SubmitGetRequest(url, encodedData)
EndIF
// ParseQueryString transforms that query string value into
// a name/value pair. This keeps you needing to parse
// that query string yourself.
LeaveSr HttpUtility.ParseQueryString(responseString)
EndFunc
BegFunc SubmitPostRequest Type(*String)
DclSrParm Url Type(*String)
DclSrParm Data Type(*String)
DclFld Encoding Type(ASCIIEncoding) New()
DclFld Request Type(HttpWebRequest)
DclFld Response Type(HttpWebResponse)
DclFld RequestStream Type(Stream)
DclFld ResponseStream Type(Stream)
DclFld ResponseString Type(*String)
DclFld sr Type(StreamReader)
DclArray DataAsBytes Type(byte) Rank(1)
DataAsBytes = Encoding.GetBytes(Data)
Request = WebRequest.Create(Url) *As HttpWebRequest
Request.Method = 'POST'
Request.ContentType = 'application/x-www-form-urlencoded'
Request.ContentLength = DataAsBytes.Length
Try
// Send the request to the server.
RequestStream = Request.GetRequestStream()
RequestStream.Write(DataAsBytes, 0, DataAsBytes.Length)
RequestStream.Close()
Catch error Type(System.Exception)
DclFld x Type(*String)
x = error.Message
// Handle exception error here.
EndTry
// Fetch response from server as a string.
Response = Request.GetResponse() *As HttpWebResponse
If (Response.StatusCode = HttpStatusCode.OK)
ResponseStream = Response.GetResponseStream()
sr = *New StreamReader(responseStream)
ResponseString = sr.ReadToEnd()
sr.Close()
Else
// Handle HttpStatusCode not OK here.
EndIf
LeaveSr ResponseString
EndFunc
BegFunc SubmitGetRequest Type(*String)
DclSrParm Url Type(*String)
DclSrParm Data Type(*String)
DclFld Encoding Type(ASCIIEncoding) New()
DclFld Request Type(HttpWebRequest)
DclFld Response Type(HttpWebResponse)
DclFld RequestStream Type(Stream)
DclFld ResponseStream Type(Stream)
DclFld ResponseString Type(*String)
DclFld sr Type(StreamReader)
Url = String.Format('{0}?{1}', Url, Data)
Request = WebRequest.Create(Url) *As HttpWebRequest
Request.Method = 'GET'
Try
// Send the request to the server.
requestStream = Request.GetRequestStream()
requestStream.Close()
Catch error Type(System.Exception)
// Handle exception error here.
EndTry
// Fetch response from server as a string.
Response = Request.GetResponse() *As HttpWebResponse
If (Response.StatusCode = HttpStatusCode.OK)
responseStream = Response.GetResponseStream()
sr = *New StreamReader(responseStream)
responseString = sr.ReadToEnd()
sr.Close()
Else
// Handle HttpStatusCode not OK here.
EndIf
LeaveSr responseString
EndFunc
BegFunc CollectSubmitData Type(NameValueCollection)
DclFld SubmitData Type(NameValueCollection) New()
SubmitData.Add('AccountNumber', textboxAccountNumber.Text)
SubmitData.Add('PaymentType', textboxPaymentType.Text)
SubmitData.Add('TransType', textboxTransType.Text)
SubmitData.Add('Amount', textboxAmount.Text)
LeaveSr SubmitData
EndFunc
// Encode a NameValueCollection and return as ampersand-separated string.
BegFunc EncodeData Type(*String)
DclSrParm SubmitData Type(NameValueCollection)
DclFld Items Type(List(*Of *String)) New()
ForEach Key Type(*String) Collection(SubmitData)
Items.Add(String.Format('{0}={1}', Key, System.Web.HttpUtility.UrlEncode(SubmitData[key])))
EndFor
LeaveSr String.Join('&', Items.ToArray())
EndFunc
BegFunc GetUrlWithPort Type(*String)
DclSrParm ASPXPage Type(*String)
DclFld Port Type(*String)
If HttpContext.Current.Request.Url.Host.ToLower() = 'localhost'
Port = HttpContext.Current.Request.Url.Port
LeaveSr String.Format('http://localhost:{0}/{1}', Port, ASPXPage)
Else
LeaveSr ASPXPage
EndIf
EndFunc
BegSr ShowDataReceived
DclSrParm DataReceived Type(NameValueCollection)
DclFld Buffer Type(StringBuilder) New()
buffer.Append('Data received from server:<br/>')
ForEach Key Type(*String) Collection(DataReceived)
Buffer.Append(String.Format(' • {0}={1}<br>', Key, DataReceived[key]))
EndFor
labelResponse.Text = Buffer.ToString()
EndSr
EndClass