2

I need to post this string to a url :

https://sample.nodeurl.tld/api/getObjects.sjs?object=supporter&      [email protected]&condition=Last_Modified>2010-05-05&limit=5&orderBy=Last_Modified

The issue is with multiple conditions. The following code works with a single condition, but cant figure out how to build a string with multiple conditions.

$query = array();
$query ["object"]="supporter";
$query ["condition"]="First_Name= $_POST[fname]";


curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query));
//return the transfer as a string
curl_setopt($ch, CURLOPT_POST, 1);

$output = curl_exec($ch);
2
  • Why does it have two condition=? Shouldn't that be condition[]=? Commented Sep 20, 2013 at 17:59
  • You can't have your own set of = in the URL because it's a special character. Commented Sep 20, 2013 at 18:09

2 Answers 2

1

Just make $query["condition"] into an array.

$query = array(
    'object' => 'supporter',
    'condition' => array(
        '[email protected]',
        'Last_Modified>2010-05-05'
    )
);

Then http_build_query will build you a query string that looks like:

object=supporter&condition[][email protected]&condition[]=Last_Modified>2010-05-05

I don't know about other server-side languages, but in PHP the [] after condtion makes it into an array when it's posted.

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

Comments

0

Are you trying to pass this query in POST ?If so You can just use query directly

$string = "https://sample.nodeurl.tld/api/getObjects.sjs?object=supporter& [email protected]&condition=Last_Modified>2010-05-05&limit=5&orderBy=Last_Modified";
curl_setopt($ch,CURLOPT_POSTFIELDS, $string);

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.