Can I LoadString(txt file) from the internet/web?

Monkey Targets Forums/iOS/Can I LoadString(txt file) from the internet/web?

Alex(Posted 2014) [#1]
Hello,
Subj.

I go like:
oldPriceFile = app.LoadString("http://white-zebra.com/oldprice.txt")

=> oldPriceFile is an empty string.


programmer(Posted 2014) [#2]
Use brl.httprequest to load strings asynchronously.
Example: http://source.mungo.io/docs/samples/blob/master/mak/httprequest/httprequest.monkey


DiabloV(Posted 2014) [#3]
hello. this don't work on html5 target


Alex(Posted 2014) [#4]
programmer,
Thank you! Works as a charm on iOS.

DiabloV,
Yes, doesn't work on html5.


Soap(Posted 2014) [#5]
Are you trying to load text on the same domain or different domain? Last time I tested this it worked for HTML5 targets if I remember... and I have a live version where this works, but things may have changed in later version in some way.

http://en.wikipedia.org/wiki/Same_origin_policy

Test adding a crossdomain.xml to the root of your domain with this text. You would want to have it set to only work on your sites most likely.

<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>


programmer(Posted 2014) [#6]
Test adding a crossdomain.xml to the root ...
The crossdomain.xml file only works within Flash apps.


Alex(Posted 2014) [#7]
I don't need html5 for my project, so I didn't try to fix.
IOS works well.

I use it like this:
Global HTTPreq := New HTTPreqClass

Class HTTPreqClass 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()
		
		oldPriceFile = req.ResponseText()
		
	End
	
	Method GetTxtFromWeb:Void(path:String)

		get_req = New HttpRequest( "GET", path, Self )
		get_req.Send()

	End

End


HTTPreq.GetTxtFromWeb( "http://white-zebra.com/oldprice.txt" )