PHP通过CURL POST发送JSON

I cannot figure out why this function is not POSTing, any ideas? Thanks! I am trying to send JSON data to a server, and I am getting no error or feedback, the var_dump($response) just gives me 'null'.

function postToDatabase($data, $thingName){
  $content = json_encode($data);

  $curl = curl_init('http://someurl.com/thing'. $thingName .'/otherthing');
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($curl, CURLOPT_HEADER, false);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_HTTPHEADER,
    array("Content-type: application/json"));
  curl_setopt($curl, CURLOPT_POST, true);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //curl error SSL certificate problem, verify that the CA cert is OK

$result     = curl_exec($curl);
$response   = json_decode($result);
var_dump($response);
curl_close($curl);
}


/* post to url */
postToDatabase($someData, $thingName);

my JSON $content:

{
    "email": null,
    "stripeToken": "aidfat9s8d7ftas7df9asjd7fy0aksd",
    "stripeShippingName": "A Test User",
    "stripeShippingAddressLine1": "1we2e12",
    "stripeShippingAddressZip": "62650",
    "stripeShippingAddressState": "IL",
    "stripeShippingAddressCity": "Jacksonville",
    "stripeShippingAddressCountry": "United States",
    "products": [
        {
            "productId": "897349864",
            "sizeId": "4",
            "colorId": "6",
            "units": 1
        }
    ]
}
查看全部
dsv768456
dsv768456
2014/04/17 19:37
  • curl
  • json
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复