Structure of parameters in POST

Structure of parameters in POST

by Jackie Smile -
Number of replies: 3

Hello, I'm basically hitting the brick wall with this and my other two posts don't get any reply. I can't believe it is that hard. So I'm trying once again with a fresh new start from the ground up.

How can I send data to a webservice using POST? What I'm particularly interested in is how the params structure would look like and their corresponding declaration in the prameters function inside the externallib.php file. I already can distinguish between GET and POST and other stuff, only the parameter description drives me nuts. I would appreciate it very much if someone could post a short example and relieves me from this struggle.

 

Some details

part of my proposed externallib ..._parameters():

...
return new external_function_parameters(
    array(
        'foo' => new external_value(PARAM_TEXT, 'just a test')
    )
)
...

I would expect the params to be something like

$foo= 'bar';
$params=array($foo);

But I always get the "Calling parameters do not match signature" error. i don't know how I could solve this

Average of ratings: -
In reply to Jackie Smile

Re: Structure of parameters in POST

by Hubert Chathi -

Try $params to array('foo' => $foo).

In reply to Hubert Chathi

Re: Structure of parameters in POST

by Jackie Smile -

Thanks for your reply Hubert. Actually it was how I thought it should be. I was just putting the data in another array before and that caused the error.
However my real problem is still not solved. I want to use a structure similar to the create_users function so I'm posting that instead. From examples I found this should work but I don't manage to accomplish that...

client:

...
$user = new stdClass();
$user->username = 'testusername';
$users = array( $user );
$params = array( 'users' => $users );
...
$post = xmlrpc_encode_request($functionname, $params);

That should relate to the parameter description in externallib.php: 

...
return new external_function_parameters(
    array(
        'users' => new external_multiple_structure(
            new external_single_structure(
                array(
                    'username' => new external_value(PARAM_RAW, 'Username'),
...


and the parameter validation:

...
$params = self::validate_parameters(self::create_users_parameters(), array('users'=>$users));
...


I still get the "Calling parameters do not match signature" error. What is wrong here? I'm using the XML-RPC if that is of concern

In reply to Jackie Smile

Re: Structure of parameters in POST

by Jackie Smile -

OK I found that one too...

where it says: $params ) array( 'users' => $users );  it should instead be $params = array($users);

The explanations on the web are really confusing about when to put it into an array and if there should be a key or not..