1

Here is my code,

$ip = array([0]=>'1.1.1.1' [1]=> '2.2.2.2')

$ux = RestClient::post($url,array('requestType'=>'Ip', 
                                                     'username' => 'user', 
                                                             'pass' =>'user',
                        'type'=>$type,
                        'ip'=>array($ip)                            
                            ));
  echo $ux->getResponse();

How to post 'ip' at server side? When I use $_POST['id'], it returns 'Array' as string.

1
  • what about, convert the array info json? Commented Nov 23, 2012 at 11:31

2 Answers 2

7

You can't post an array. You have to serialize it to a string. That could be the standard form encoding method:

ip=1.1.1.1&ip=2.2.2.2

That could be JSON:

{ "ip" : [ "1.1.1.1", "2.2.2.2" ] }

That could be some XML format:

<ips>
    <ip>1.1.1.1</ip>
    <ip>2.2.2.2</ip>
</ips>

That could be something else.

… but what you need to do depends on what the API you are submitting to expects.

Sign up to request clarification or add additional context in comments.

3 Comments

Shouldn't that be ip[]=1.1.1.1&ip[]=2.2.2.2? (Note the brackets)
@fireeyedboy — No. That's a peculiarity of PHP's form parsing routines. Here PHP is the client, the server is unspecified.
Ah right, I wasn't sure about how other platforms deal with this. Thanks.
0

I suspect you need to use JSON for your array. Convert it with json_encode( $array )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.