Is there an equivalent way to handle GET and POST in Web 2? Everything I have tried in Web 2 Fails. Here is working code in a Web 1
Dim ReqMethod,ReqString As String
ReqMethod = Uppercase(Request.Method)
ReqString = Request.QueryString
Select Case Lowercase(Request.Path)
Case "folderdata"
If ReqMethod = "GET" Then
LogTransactions("GET Received From: " + Request.RemoteAddress )
LogTransactions("Query String Received: + ReqString)
// Return true to signal that we handled the request
Return True
Else
//Return false since we only handle POSTs
Return False
End If
Else
// Don't handle any other requests
LogExceptions("Request Path " + ReqMethod + " not handled")
LogTransactions("Request Path " + ReqMethod + " not handled")
Return False
End Select
Trying to show the query string in a TextArea gives a nil object exception and just storing the query string in a variable stores the string but it still returns a 404 Not Found
Function HandleURL(Request As WebRequest, Response As WebResponse) Handles HandleURL as Boolean
Var bool As Boolean
Var ReqMethod,ReqString As String
ReqMethod = Uppercase(Request.Method)
ReqString = Request.QueryString
Select Case Lowercase(Request.Path)
Case "folderdata"
If ReqMethod = "GET" Then
App.QryStrng = ReqString
// Return true to signal that we handled the request
Return True
Else
// Return false since we only handle GET
Return False
End If
Else
// Return false since it's the wrong folder
Return False
End Select
End Function
I’m getting that Response doesn’t exist when compiling. I’ve tried various things like Request.Response and WebRequest.Response but they don’t have a Status or Write property.
Response is a variable passed to you via the Event. The compiler saying it doesn’t exist might mean that you’re writing code somewhere that doesn’t have the Response object.
Here’s a quick sample project that might help you see what’s going wrong: HandleURL.xojo_xml_project
One other thing. If I try to use the QueryString in a Text Field I get a Nil Object Exception. I’ve tried storing it in a variable first also and it stores fine but I still get Nil Object Exception if I try to use the variable from the HandleURL event.
Function HandleURL(Request As WebRequest, Response As WebResponse) Handles HandleURL as Boolean
Var ReqMethod,ReqString As String
ReqMethod = Uppercase(Request.Method)
Select Case Lowercase(Request.Path)
Case "folderdata"
If ReqMethod = "GET" Then
WebPage1.TextField1.Text = Request.QueryString
Response.Status = 200
Response.Write("Ok")
// Return true to signal that we handled the request
Return True
Else
// Return false since we only handle GET
Return False
End If
Else
// Return false since it's the wrong folder
Return False
End Select
End Function
While doing what you want does require an excessive amount of bending over backwards (you can’t start a session anywhere other than the root), I don’t think it’s ever required a Timer.
The timer just updates the log entries on the web page if you are viewing the page. Otherwise the GET just runs in the background triggering app level stuff. In this case it will save the data as a JSON file for another system to pick up at regular intervals. I have to use a GET because the PLC board doesn’t support a POST with a JSON payload.