यहाँ मेरी कोड,PHP कर्ल के साथ जेएसओएन डेटा कैसे पोस्ट करें?
$url = 'url_to_post';
$data = array("first_name" => "First name","last_name" => "last name","email"=>"[email protected]","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
आप गायब नहीं '$ data_string' को बदलने' $ डेटा' 'json_encode()' का उपयोग कर रहे ??? कोड की इस पंक्ति को न देखें ... – shadyyx
क्षमा करें मैंने यहां नहीं लिखा था लेकिन मेरे कोड में मैंने 'code' $ data_string = json_encode ($ डेटा) लिखा था; 'कोड' और टिप्पणियों में कोड कैसे लिखना है? टिप्पणियों में मैं लाइन ब्रेक नहीं लिख सकता और इसलिए कोड कैसे लिखूं? – user1463076