Class brl.httprequest.HttpRequest - leonard-thieu/monkey GitHub Wiki
The httprequest module allows you to perform http requests such as GET and POST.
New ()
New ( requestMethod:String, url:String, onComplete:IOnHttpRequestComplete )
BytesReceived : Int ()
Open : Void ( requestMethod:String, url:String, onComplete:IOnHttpRequestComplete )
ResponseText : String ()
Send : Void ()
Send : Void ( data:String, mimeType:String, encoding:String )
SetHeader : Void ( name:String, value:String )
Status : Int ()
The httprequest module allows you to perform http requests such as GET and POST.
Import mojo
Import brl.httprequest
Class MyApp Extends App Implements IOnHttpRequestComplete
Field get_req:HttpRequest,post_req:HttpRequest
Method OnHttpRequestComplete:Void( req:HttpRequest )
If req=get_req
Print "Http GET complete!"
Else
Print "Http POST complete!"
Endif
Print "Status="+req.Status()
Print "ResponseText="+req.ResponseText()
End
Method OnCreate()
get_req=New HttpRequest( "GET","http://posttestserver.com",Self )
get_req.Send
post_req=New HttpRequest( "POST","http://posttestserver.com/post.php",Self )
post_req.Send "Hello World!"
SetUpdateRate 60
End
Method OnUpdate()
If KeyHit( KEY_CLOSE ) Error ""
UpdateAsyncEvents
End
Method OnRender()
Cls
DrawText "Http GET bytes received="+get_req.BytesReceived(),0,0
DrawText "Http POST bytes received="+post_req.BytesReceived(),0,12
End
End
Function Main()
New MyApp
End
Creates a new HttpRequest object.
Method New ( requestMethod:String, url:String, onComplete:IOnHttpRequestComplete )
Creates a new http request object and opens it.
The requestMethod parameter should be GET, HEAD, POST, PUT, DELETE or any http method recognized by the server.
Method BytesReceived : Int ()
Returns the total number of bytes received.
Method Open : Void ( requestMethod:String, url:String, onComplete:IOnHttpRequestComplete )
Opens an http request.
This effectively 'resets' the internal state of the http request.
The requestMethod parameter should be GET, HEAD, POST, PUT, DELETE or any http method recognized by the server.
Method ResponseText : String ()
The response text returned by the server once the request has completed.
Method Send : Void ()
Sends an http request.
Once complete, the OnHttpRequestComplete method of the IOnHttpRequestComplete object passed to the construtor will be called.
Your application must continously call UpdateAsyncEvents at regular intervals (for example, once per OnUpdate) while an http request operation is in progress.
Sends an http request with data.
Send sets the request's Content-Length header to the encoded length of data.
If mimeType is not an empty string, Send also sets the request Content-Type header.
Once complete, the OnHttpRequestComplete method of the IOnHttpRequestComplete object passed to the construtor will be called.
Your application must continously call UpdateAsyncEvents at regular intervals (for example, once per OnUpdate) while an http request operation is in progress for it to complete.
Sets an http request header option.
Method Status : Int ()
The status returned by the server once the request has completed.