loadVarable can't send data to another site!

This is my script


myButton.onRelease=function(){
        _root.loadVariables("http://www.apisite.com/try.php?name=" + theName.text + "", "GET");
        
}

But it can’t send data to that site. It just display “Waiting for www.apisite.com…” in the status bar and don;t send anything.
p/s : I set Local Playback Security to “Access Network Only” and turn off my Firewall

sending requires you to use “POST” not “GET”

i changed my script but nothing happened
I read some resource said that we can’t send data to external hosting because of flash security?
is it true ?

no not at all… no one has the right to say anything about flash :)… its so tender… and yet so strong.

[From Macromedia docs]

loadVariablesNum().

Availability: ActionScript 1.0; Flash Player 4 - Behavior changed in Flash Player 7. Flash 4 files opened in Flash 5 or later are converted to use the correct syntax.

Parameters
url:String - An absolute or relative URL where the variables are located. If the SWF file issuing this call is running in a web browser, url must be in the same domain as the SWF file; for details, see the Description section.

level:Number - An integer specifying the level in Flash Player to receive the variables.

method:String [optional] - Specifies an HTTP method for sending variables. The parameter must be the string GET or POST . If there are no variables to be sent, omit this parameter. The GET method appends the variables to the end of the URL and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for long strings of variables.


For a more modern and non orthodox solution try loadVars class instead.

I highly recommend using a LoadVars Object vs. loadVariables. Can peek at it here.

With LoadVars, you can load, send or sendAndLoad. If you only use send, however, a new browser window will open and take you to the page you’re trying to send data to. To avoid that you want to use sendAndLoad. It basically sends the data, then expects some type of data to be sent back to flash - that can be a simple print or echo (in a php script) - or, I think you can not have anything be sent back to flash if you prefer. loadVariables (I believe) acts in this manner too in that, it does load data to the server, but it also is trying to load data back into flash. This is where your problem lies. That server doesn’t want other servers to try to access data from it - and even though you may only need to push data there, its trying to get data as well. In this case, you’ll need a crossdomain.xml file on that server you’re trying to talk to - just google “flash crossdomain.xml” and you’ll find what you need.

so, yes, you’re correct in saying the following, but you need an extra step:

I read some resource said that we can’t send data to external hosting because of flash security?
is it true ?
You’ll need that crossdomain.xml file up on that other server that allows it to accept calls from whatever server your swf is on. Flash can communicate cross server, but its smart enough to know that the developer needs to have permission to do this - and the crossdomain.xml system is the permission slip.

Also, take a peek at these security docs - a lot of great info:
http://www.adobe.com/devnet/flashplayer/articles/flash_player_9_security.pdf
http://www.adobe.com/devnet/flashplayer/articles/flash_player_8_security.pdf

crossdomain.xml is not needed if your backend script and swf are on the same domain.

it is used only when swf is serving from a different domain than the one your server side script resides in :slight_smile:

[quote=sparkdemon;2333273]crossdomain.xml is not needed if your backend script and swf are on the same domain.

it is used only when swf is serving from a different domain than the one your server side script resides in :)[/quote]

true - but he’s sending to a diff. domain from what I see in the first thread.

if thi si the actual url http://www.apisite.com/try.php
then you will definitely face problem… :slight_smile:

normally people give some exampe url… so i didnt take it seriously :slight_smile:

Read up on it.

Thanks for everyone, i understand about this.
:slight_smile:
I think this security method in Flash is needed because i read some threads discussing about ddos attacking through flash by looping sending data to the victim server