lundi 21 décembre 2015

Sending Json Objects to Laravel via Post

I'm currently having some dificulty understanding how the framework works, as in sending data from as3. Currently I have this code on Laravel:

Route::get('HelloWorld',function(){return "Hello World";});
//Method returns a Hello World - works

Route::post('Register/{nome?}' ,'AccountController@Register');
//Method returns a string saying "How are you" - doesn't process

On AccountController:

public function Register($nome){
    return "How are you";
}

On my AS3, I'm currently doing this for these methods:

request.url = "http://myip/HelloWorld";
request.requestHeaders = [new URLRequestHeader("Content-Type", "application/json")];
request.method = URLRequestMethod.GET;

var loader: URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, receiveLoginConfirmation);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, notAllowed);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, notFound);
loader.load(request);
//Works


var variables: URLVariables = new URLVariables();
variables.nome = "Pedro";

request.url = "http://myip/Register";
request.requestHeaders = [new URLRequestHeader("Content-Type", "application/json")];
request.data = variables;
request.method = URLRequestMethod.POST;

var loader: URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, receiveRegisterConfirmation);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, notAllowed);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, notFound); 
loader.load(request);
//Trying to understand the error, it gives me httperror 500, if I comment request.data it gives me httperror 405.

The doubt im having is understanding how to proceed to receive information in laravel AND determine if my as3 request is correct.

Aucun commentaire:

Enregistrer un commentaire