- Joined
- Jul 17, 2017
- Messages
- 76
Hi,
I'm picking up my work from here on getting https requests working for my game. GET/POST requests work fine for html5 but are giving me malformed errors for desktop.
With this demo, I see GET requests trigger a 404 and POST requests return a 400 - Request Line is too large.
Steps to replicate:
- Using Cerberus v2020-05-09b on windows.
- Overwrite the curl and msvc folders in targets/glfw3/template with MikeHart's files from the aforementioned thread. (not doing so will cause imports of brl.httprequest to not compile).
- Compile the above code for GLFW. Post/get requests fail.
- Compile the above code for HTML5. Post/get requests succeed.
Thanks for any help, and I'm happy to help troubleshoot this!
I'm picking up my work from here on getting https requests working for my game. GET/POST requests work fine for html5 but are giving me malformed errors for desktop.
With this demo, I see GET requests trigger a 404 and POST requests return a 400 - Request Line is too large.
Code:
Strict
Import mojo
Import brl.httprequest
Function Main:Int()
New Game()
Return 0
End
Class Game Extends App
Field server:HttpManager
Const HTTPS$ = "https://"
Field getAddress$ = "httpbin.org/get"
Field postAddress$ = "httpbin.org/post"
Method OnCreate:Int()
SetUpdateRate(60)
server = New HttpManager()
Print "Initialized!"
Return 0
End
Method OnUpdate:Int()
UpdateAsyncEvents()
If KeyHit(KEY_SPACE) Then SendGet()
If KeyHit(KEY_ENTER) Then SendPost()
If KeyHit(KEY_ESCAPE) Then EndApp()
Return 0
End
Method OnRender:Int()
Cls()
DrawText "ENTER - GET request: " + getAddress,0,0
DrawText "SPACE - POST request: " + postAddress,0,16
DrawText "ESCAPE - exit",0,32
If server.lastResponse <> Null
DrawText "Http status="+server.lastResponse.Status(),0,116
DrawText "Http bytes received="+server.lastResponse.BytesReceived(),0,132
DrawText "Http text received="+server.lastResponse.ResponseText(),0,148
Endif
Return 0
End
Method SendGet:Void()
Print ""
Print " >> assembling GET..."
Local req:HttpRequest
Local address$ = HTTPS + getAddress
Print address
req = New HttpRequest( "GET", address, server)
req.SetHeader("accept", "application/json")
req.Send()
Print " >> sent GET to " + address
End
Method SendPost:Void()
Print ""
Print " >> assembling POST..."
Local req:HttpRequest
Local address$ = HTTPS + postAddress
Local data$ = "{name: 'peahen'}"
'send the post request
req = New HttpRequest( "POST", address, server)
req.SetHeader("accept", "application/json")
req.Send(data, "application/json")
Print " >> sent POST to " + address + " with data " + data
End
End
Class HttpManager Implements IOnHttpRequestComplete
Field lastResponse:HttpRequest
Method OnHttpRequestComplete:Void( req:HttpRequest )
Print "HTTP request complete! Status="+req.Status()
Print " Text="+req.ResponseText()
lastResponse = req
End
End
Steps to replicate:
- Using Cerberus v2020-05-09b on windows.
- Overwrite the curl and msvc folders in targets/glfw3/template with MikeHart's files from the aforementioned thread. (not doing so will cause imports of brl.httprequest to not compile).
- Compile the above code for GLFW. Post/get requests fail.
- Compile the above code for HTML5. Post/get requests succeed.
Thanks for any help, and I'm happy to help troubleshoot this!