some questions to HttpRequest()
Monkey Forums/Monkey Programming/some questions to HttpRequest()
| ||
I try to get the new HttpRequest() Class working. My problem is, that my code should run on HTML5 and ANDROID. Until now I used MNET for both: HTML5 and ANDROID. Because of problems with Android 4 now I have to change something. In future I want to use Mnet for HTML5 and Marks HttpRequest()for the Android http requests Marks sample code (from the API doc) works perfect on my smartphone. It uses callbacks and therefore it implements IOnHttpRequestComplete() to the Class MyApp Class MyApp Extends App Implements IOnHttpRequestComplete I cannot do that, because the builder brings an error on HTML5 target. Can I implement this to a new class AndroidComm instead of App: Strict Import mojo Import mnet #If TARGET="android" Import brl.httprequest #Endif Class Game Extends App Field Server:AndroidComm Method OnUpdate() If KeyHit( KEY_ESCAPE ) Error "" UpdateAsyncEvents End End Class AndroidComm Implements IOnHttpRequestComplete Field req:HttpRequest .... Method OnHttpRequestComplete:Void( req:HttpRequest ) Print "Http GET complete!" Print "Status="+req.Status() Print "ResponseText="+req.ResponseText() End End Or is it necessary, that the callbacks and UpdateAsyncEvents() must be in the App class? |
| ||
> Or is it necessary, that the callbacks and UpdateAsyncEvents() must be in the App class? No, UpdateAsyncEvents and callbacks can be anywhere, so your approach should work. You can also still call UpdateAsyncEvents on html5 too - it just wont do anything if there's nothing async happening. Another 'quick and dirty' way to do it would be: #If TARGET="html5" Class Game Extends App #Else Class Game Extends App Implements IOnHttpRequestComplete #Endif Method OnCreate()... But I think your way is nicer. |
| ||
When I now use the HttpRequest() I get three more characters at the beginning of the answer:THANK YOU Does this have todo anything with UTF8? The php script only echos this string: echo "THANK YOU"; If I call the php-script from the browser... http://www.midimaster.de/temp/score.php?L=1 ...I only get back THANK YOU Do I do something wrong, or is it normal and I only have to cut away the three characters? *** EDIT *** solved: I had switched something in my text edit. That added the 4 bytes in front of every text and caused the problems... |