WebRequest best practice

Hi team,

I’ve never quite been sure how to handle and setup a data structure to capture data from a web request. I know it’s an array but to date I’ve been doing something like this:

var ID1, ID2,ID3,ID4,ID5,ID6,ID7,ID8,ID9,ID10 as integer
ID1 = val(datain.Parameter("ID1"))
ID2 = val(datain.Parameter("ID2"))
ID3 = val(datain.Parameter("ID3"))
ID4 = val(datain.Parameter("ID4"))
ID5 = val(datain.Parameter("ID5"))
ID6 = val(datain.Parameter("ID6"))
ID7 = val(datain.Parameter("ID7"))
ID8 = val(datain.Parameter("ID8"))
ID9 = val(datain.Parameter("ID9"))
ID10 = val(datain.Parameter("ID10"))```

I there a better way to pull the array into a series of integers based on parameter string names?  I may have dozens or hundreds of ID's coming into my site in the future and wouldn't want to have to recreate like this.

Thanks all!

There is probably a way to access .Parameter with an index instead of a key.

You might want to let on what the datatype of ‘datain’ is.

Thanks Matthew,

Datatype is the WebRequest array of parameters (strings). I guess I have to create a dictionary with all possible parameter names (created programatically) and then test to see if I’ve received them? I could null check then as well I guess. Not all parameters will come in each time the event is fired.

Ahh. OK. There is a possibility you have misunderstood something here.

Let’s say in the address bar of a browser I type
http://xojo-app.contoso.com/my-data-receiver?id=101&first=james&last=mullins

And the request is hoovered up by a WebRequest object named dataIn

dataIn.Parameter(“id”) will return “101”
dataIn.Parameter(“first”) will return “james”
dataIn.Parameter(“last”) will return “mullins”
dataIn.Parameter(“id1”) will return a null string “” because a parameter named id1 did not appear in the request sent by the browser.

Key point. .Parameter is an access ‘method’ rather than an array type.

Exactly what you asked for seems a bit odd but can be done something like this.


// assign 10 integer values passed as parameters named "IDn" to an integer array 

var idArray as integer(10)
for iIndex as integer = 1 to 10
  idArray(iIndex) = dataIn.Parameter("ID" + CStr(iIndex)).ToInteger
next