I am hoping someone can spot what is missing here. I am getting null result from curl-ing a page with json post variables.

I try this url in my Firefox browser -


(#somevar.someothervar are irrelevant, I think, as I get the curl variables from Firebug below.)

In Firebug, this shows:

POST http://www.targetsite.com/ajax/search.xml

In Firebug, below this link are tabs for: Headers, Post, Response, XML and Cookies. Post tab shows like:

VAR1           1
VAR2           "2012-09-12"
VAR3           null
CACHED         []
OPTIONS        null

To prove there is output, the Firebug Response tab shows:

<?xml version="1.0" encoding="utf-8"?>
<JSON> various JSON encoded stuff </JSON>

The above is what I am trying to curl.

My php code:

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, 1);

  //target page from Firebug above:
curl_setopt($ch, CURLOPT_URL, "http://www.targetsite.com/ajax/search.xml";);

  //I was not sure how to represent CACHED [], so set it to null
  $data = array(
    "VAR1" => 1,
    "VAR2" => "2012-09-12",
    "VAR3" => null,
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

  //make the request
  $result = curl_exec($ch);

  //this returns null

Any ideas where to go with this? Maybe I need to include the Cookies? I use the above php and curl functions normally so it's all installed on the server.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to