views:

274

answers:

4

I am using AMFPHP with great success to link my database with my Flex application. However I want to be able to test the remoting requests outside of flash, by typing something like:

http://localhost/amfphp/gateway.php?%5BWHAT DO I PUT HERE]

What do I put after the questionmark in order to have the browser (or a C++ http component) call the amfphp service, so that the http request needn't "initiate" from flash.

A: 

AMF being a binary format, things are probably not going to be that simple : you'll have to find out how your data is encoded...

As a first step, maybe you could, from your gateway.php script, just dump everything it receives to a file, when it's called from your flash component ?

This way, you could see how the received data looks like (and you'd know if it's passed in POST, or in GET).

Depending on what that data looks like, maybe you'll be able to "forge" a request to your server -- but I don't think it'll be as simple as just calling an URL from your browser...

Pascal MARTIN
A: 

Considering the AMFPHP gateway is just a mechanism to translate (from/to binary) and dispatch to a class/method with various incoming parameters and finally a return() of data - can you just unit-test directly against the method, thus skipping the entire AMF layer?

Alister Bulman
+1  A: 

It sounds like you want to make an AMF call from PHP. You can't do this directly from a browser. The data would be returned in the binary AMF format, which of course PHP or a browser can't handle directly. I don't even think it can make the request.

You'll need a AMF client to make the call and decode the data - I suggest using SabreAMF.

Sabre AMF homepage

This is what simple client method call code looks like.

require 'SabreAMF/Client.php';

function make_request($param1,$param2){
$client = new SabreAMF_Client('http://your.server/amfphp/gateway.php'); 
return $client->sendRequest('your_amf_service.yourAMFmethod',array($param1, $param2));
}

you then invoke this like

$result=make_request('cow',300);

and it returns an array.

You'd probably want to set up a PHP class with all of your methods so you can call each one easily, of course.

Alex JL
A: 

AMFPHP has the service browser, which lets you simulate calls to your server-side service and see the responses. It basically does an internal CURL request back to the same service file and passes in the arguments you provided, and acts as if it was done directly from the client-side Flash app.

Marc B