ActionScript.org Forums

ActionScript.org Forums (http://www.actionscript.org/forums/index.php3)
-   ActionScript 3.0 (http://www.actionscript.org/forums/forumdisplay.php3?f=75)
-   -   URLLoader using POST fails to send variables (http://www.actionscript.org/forums/showthread.php3?t=189628)

pseudobiotic 11-19-2008 06:11 PM

URLLoader using POST fails to send variables
 
hopefully this is simple and I'm just missing something obvious. I'm trying to hit a php page using POST data and load the response. what actually happens is the php page is hit using POST but without data. if I navigateToURL with the URLRequest instead of URLLoader.load, the data is sent.

Code:

import flash.events.*;
import flash.net.*;

some_button.addEventListener( MouseEvent.CLICK, _handle_click);

function _handle_click( in_mouse_event:MouseEvent):void {
       
        var url_variables:URLVariables = new URLVariables();
        url_variables.a = 1;
        url_variables.b = 2;

        var url_request:URLRequest = new URLRequest( "index.php");
        url_request.method = URLRequestMethod.POST;
        url_request.data = url_variables;
       
        var url_loader:URLLoader = new URLLoader();
        url_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
        url_loader.addEventListener( Event.COMPLETE, _handle_complete);
        url_loader.addEventListener( IOErrorEvent.IO_ERROR, _handle_io_error);
        url_loader.load( url_request);
        //navigateToURL( url_request);
}

function _handle_complete( in_event:Event):void {
        trace( "complete");
}
function _handle_io_error( in_event:IOErrorEvent):void {
        trace( "io error");
}

thank you for any help

creatify 11-19-2008 06:28 PM

I don't see anything wrong with your code unless I'm missing something... what does your php look like, is it set to grab the vars _POST or _GET?

pseudobiotic 11-19-2008 08:20 PM

thanks for your reply creatify! the php isn't doing anything other than
PHP Code:

print_r$_POST); 

I'll make an example and post it.

pseudobiotic 11-19-2008 09:37 PM

sorry! I'd been misdiagnosing a problem. I'd been watching the requests and responses using firebug (and firebug lied!). the code had been working correctly all along. I only figured it out after trying to build an example that traced out the response w/o firebug. thanks for your help!

SarK0Y 11-20-2008 12:26 AM

Hi, pseudobiotic
i use so:
var sendData="param1=xxx.xx&param2=yyyy...yy"
var variables:URLVariables = new URLVariables(sendData);
var request:URLRequest = new URLRequest();
request.url = "web.com";
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, function(evt:Event):void {
completeHandler(evt, clik.target)});

pseudobiotic 11-20-2008 12:30 AM

cool! thanks for your reply SarK0Y

maximillion 11-21-2008 05:58 PM

pseudobiotic - I have this exact problem - all POST data is empty when I replay the request in Live HTTp Headers (firefox add-on) the POStT array is empty?? although I can see POST data in the header???

navigateToURL() - posts the data just fine and this is really baffling me



ActionScript Code:
var variables:URLVariables = new URLVariables(postData); variables.key = 'dsfsgh';          variables.desc = 'dsfsfds'          var request:URLRequest = new URLRequest(_submissionURL); request.method  = URLRequestMethod.POST;            request.data = variables;            _subLoader = new URLLoader(); _subLoader.addEventListener( Event.COMPLETE, submissionCompleteHandler ); _subLoader.addEventListener( HTTPStatusEvent.HTTP_STATUS, onHTTPStatus ); _subLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); _subLoader.dataFormat = URLLoaderDataFormat.VARIABLES _subLoader.load( request );

can anyone help?

cheers

maximillion 11-21-2008 08:16 PM

the solution to my problem was that 'replaying' the request from flash in 'http live headers' and 'tamper data' add-ons for firefox didnt not replay them as flash had sent them and caused problems reading the POST data in php.

I hope that helps others!


All times are GMT. The time now is 01:55 AM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger