Tôi nhận được phản hồi mong muốn khi tôi gửi yêu cầu cURL từ số PHP của tôi.
Yêu cầu của tôi là như thế này.Cách chuyển mảng đối số tới cURL trong dòng lệnh?
$data = array ("[product[name]]" => "nw",
"[product[handle]]" => 150,
"[product[interval_unit]]" => "day",
"[product[interval]]" => 1,
"[product[price_in_cents]]" => 0,
"[product[initial_charge_in_cents]]" => 14200,
"[product[return_url]]" =>"http://mytrial.com/office/selfie/themes/adcampaign/56cee935-185c-4dfs-asdfa-2b6b0ae84a4d",
"[product[return_params]]" => "id={subscription_id}&customer_id={customer_id})");
$url="http://mytrial.com/office/selfie/themes/adcampaign/346423/products.json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, 'sdfkjas2kjsd:x');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$res = curl_exec($ch);
curl_close($ch);
Nó hoạt động bình thường. Tôi muốn thực hiện yêu cầu tương tự trong dòng lệnh. Đầu tiên tôi đã mã hóa mảng và tôi đã thử với lệnh này
curl -u sdfkjas2kjsd:x -H Accept:application/json -H Content-Type:application/json -x POST --data product[name]=nw&product[handle]=142&product[interval_unit]=day&product[interval]=1&product[price_in_cents]=0&product[initial_charge_in_cents]=14400&product[return_url]=http:\/\/54.145.218.63\/dev_lpad\/launchpad\/advertisers\/adcampaign\/56cee935-185c-4349-a8a1-2b6b0ae84a4d&product[return_params]={id={subscription_id}&customer_id={customer_id}} http://mytrial.com/office/selfie/themes/adcampaign/346423/products.json
Sau đó, tôi đã nhận được lỗi.
Error: Unable to parse request body
Có cách nào để giải quyết vấn đề này không?
UPDATE : The URL provided here is a dummy value,Actually i am trying to connect with Chargify API (Recurring billing solution).
'-H Content-Type: application/json' Tại sao bạn nói vậy? – Quentin
vì tôi đang cố gắng gửi dữ liệu json –
'sản phẩm [tên] = nw & sản phẩm [xử lý] ...' không nhìn từ xa như JSON – Quentin