这是我的代码,
$url = 'url_to_post';
$data = array(
"first_name" => "First name",
"last_name" => "last name",
"email"=>"email@gmail.com",
"addresses" => array (
"address1" => "some address",
"city" => "city",
"country" => "CA",
"first_name" => "Mother",
"last_name" => "Lastnameson",
"phone" => "555-1212",
"province" => "ON",
"zip" => "123 ABC"
)
);
$data_string = json_encode($data);
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, array("customer"=>$data_string));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
'Content-Type:application/json',
'Content-Length: ' . strlen($data_string)
)
);
$result = curl_exec($ch);
curl_close($ch);
在其他页面上,我正在检索发布数据。
print_r ($_POST);
输出为
HTTP/1.1 200 OK
Date: Mon, 18 Jun 2012 07:58:11 GMT
Server: Apache
X-Powered-By: PHP/5.3.6
Vary: Accept-Encoding
Connection: close
Content-Type: text/html
Array ( )
因此,即使在我自己的服务器上,我也无法获得正确的数据,它是空数组。我想在http://docs.shopify.com/api/customer#create中使用json实现REST
抱歉我没有在这里写,但是在我的代码中我写了
—
user1463076 2012年
code
$ data_string = json_encode($ data); code
以及如何在注释中编写代码?在注释中,我无法写换行符,那么如何编写代码?
$data
成$data_string
使用json_encode()
??? 吗?看不到这行代码...