Web App times out waiting for HTTP request from client

I have a web app (running on Xojo Cloud) that is REST server, and I have been testing the API with Postman and have had no problems getting responses back. I am starting to build out the desktop client app and have hit a wall. The desktop app is getting the following response from the web app on every request:

408 Request Timeout
Request Timeout
Server timeout waiting for the HTTP request from the client

I am using URLConnection.SendSync and as best as I can tell the requests are identical to what Postman is sending.

Has anyone seen this before?

Anyone? @Greg_O_Lone ??

I don’t use SendSync, never could get it work correctly for me. I use Send and have not had any issue.
Here is an example snippit of my code.

GetPartsConnection.RequestHeader("Authorization") = "Basic " + EncodeBase64(userp)
GetPartsConnection.SetRequestContent(Tech.ToString, "application/json")

GetPartsConnection.AllowCertificateValidation = True
// Send request to web service
Try
  GetPartsConnection.Send("POST", WWWAddress + "/GetParts", 30)
Catch
  CCMenuBar1.LblStatusRefresh.Text = "Could not refresh list. Error in GetPartsConnection method."
  return
end try

I tried it with Send also, and same result. The URL connection was originally in a thread, but I tried moving it to the window and no difference.

I have used URLConnection before to hit up 3rd-party APIs, like Cisco and Salesforce, and no problems. And Postman can get a proper response from the web app, but for whatever reason, it seems like URLConnection can’t properly communicate with the web app.

I think I’ll try writing a minimal web app and desktop client to see if I can replicate the problem there.

Sooo…

Wrote a couple of minimal test apps and found that URLConnection in a desktop app will timeout with Send or SendSync when using the GET method sent to a Xojo web app. Logging on the web app shows it never gets the request. However, any other method (POST, PATCH, DELETE, etc) works just fine.

I guess I can repurpose another method to function as GET since I am controlling both ends, but you would think GET would work.

I am on MacOS 10.15.7 and Xojo 2021r1, if that helps anyone figure this out.

The web framework doesn’t have any code path that returns a 408 error. You should be looking at the web server or proxy that’s in front of your app.

@Greg_O_Lone The web app was running on Xojo Cloud when I got the 408. I get a plain old timeout exception when running the web app locally.

But that isn’t really the problem it seems.

Why would a URLConnection GET timeout when sent to a web app, and other methods work fine? I can send a GET from Postman to the same web app and get a response.

time out after how much seconds?
have u used timeout argument in URLConnection.Send?
https://documentation.xojo.com/api/networking/urlconnection.html#urlconnection-send
there are some notes about macOS
i think URLConnection does not need to be in a thread but you can sub class it
so you have your events and functionality there in your class.

and have a look what Postman send in http header at your request.

it could be that your data preparation if the request comes in is to slow.
means you have a long delay until data can send back.
if you send data rows as json do not send each field with key,value.

Xojo Cloud has Apache in front of the app. If it’s web 1, it’s simply in web server mode, but web 2 is a reverse proxy / load balancer configuration.

Could you show an example of a URLConnection GET request that is failing for you?

@Greg_O_Lone Here’s the code from the minimal client & server apps I wrote to test the problem with.

Here’s the code on the client side:

Dim content As String = “{”“request”":"“do you work?”"}" // content is irrelevant
APISocket.RequestHeader(“Accept”) = “/”
APISocket.RequestHeader(“Content-Length”) = content.Length.ToString
APISocket.SetRequestContent(content, “application/json”)
Try
Fld_Response.Text = APISocket.SendSync(“GET”, “http://127.0.0.1:8081/rest”)
Catch error As NetworkException
Fld_Exception.Text = error.Message
Catch error As RuntimeException
Fld_Exception.Text = error.Message
End

Here’s the code in HandleURL on the web app:

Dim handled As Boolean
Dim msg As String
Dim pathComponents() As String
Dim theJSON As New JSONItem

// log
msg = Request.Method + " :: " + Request.Path
System.DebugLog(msg)

// Init a few things
PathComponents = Split(Request.Path, “/”)

// process request
If PathComponents.LastIndex = -1 Then
// no endpoint specified
handled = False
Else
// write response body
Select Case pathComponents(0).Lowercase
Case “rest”
Response.Status = 200
theJSON.Value(“status”) = “it works!”
Else
Response.Status = 404
theJSON.Value(“status”) = “resource not found”
End
Response.Write(theJSON.ToString)
handled = True
End

Return handled

@MarkusR it’s a default timeout - 60 seconds i think.

I have duplicated Postman’s headers and no change.

The data being returned is minimal - Postman gets the response in less than a second

you not use the argument here
.SendSync(method, URL, timeout)
can you try some more seconds?

The timeout value really isn’t the problem. The web app never receives the GET request. Any other method works just fine.

sorry not read completely.

so postman works and can connect to your web app in xojo cloud and your desktop app not.
at least there is no incoming connection at your web app.

@MarkusR yes, correct. but only with GET. POST, PUT, PATCH, etc all work when sent from the desktop app. GET fails when the web app is running on Xojo Cloud AND when running locally in the debugger.

For the time being, I am using PUT in place of GET since I am not using PUT for anything else.

i started a test project to see this behavior …

Thanks! i would be nice to see if you can duplicate the problem

i made 2 minimal test apps and i get a response if me made a get request.
i tested with Xojo 2021r3.1 at windows 10 pc.
i started the server exe at port 9000.

my projects
https://drive.google.com/file/d/1CUaB0yHUmorr0HbX1JwyWm34Q3dieOPJ/view?usp=sharing

Great! So it’s either a Mac problem or Xojo version problem (i am using 2021r1.1).

I have a Windows10 machine I can try - i’ll see what happens.

1 Like

Ran my client test app on Windows 10. Sent a GET to my web app running on Xojo Cloud and got a response. It looks like the issue is Mac-specific.

I have a work around so I am going to keep moving forward with the project. I might try upgrading Xojo to the current version to see if that fixes anything.

Thanks @MarkusR for the help. I appreciate it.

1 Like