• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Fixed HTTP requests for glfw fail

olive

Member
3rd Party Module Dev
Tutorial Author
Patreon Bronze
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.

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!
 
From what I can see here with my dev version, it seems to work fine in GLFW.
I guess I should create a package tommorow for you and see if that works better.
 
It works! You're a miracle-worker, friend. :) Thanks so much!
 
Back
Top Bottom