我遇到了一個問題,試圖從表單內發出POST到chargify API日誌付款。PHP curl/json問題POST
但是,由於某種原因,它實際上是作爲GET發送的,因爲它返回了一個錯誤。
任何人都可以提供任何意見,我可能做錯了什麼?郵差工作正常工作發送與JSON身體POST,但我不能讓它從PHP工作。
(注:<urlmaskedforprivacy>
顯然不是我的實際代碼)
//find invoice id # using invoice number search form
$invoiceNumber = fRequest::get('invoicenumber');
$json = file_get_contents('https://<maskedforprivacy>.chargify.com/invoices.json?number=' . $invoiceNumber);
$returnedInvData = fJSON::decode($json);
$invoiceId = $returnedInvData[0]->invoice->id;
// grab form data as payment info to send to chargify
$paymentAmount = fRequest::Get('amount');
$memo = fRequest::Get('memo');
if ((isset($invoiceNumber,$paymentAmount,$memo))) {
$url = 'https://<maskedforprivacy>.chargify.com/subscriptions/' . $invoiceId . '/payments.json';
$params = array(
'payment' => array(
'amount' => $paymentAmount,
'memo' => (string)$memo
),
);
// encode as json
$content = FJSON::encode($params);
// send to chargify
$curl = curl_init($url);
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);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 201) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($curl);
$response = json_decode($json_response, true);
}
請張貼你得到的輸出。 –
錯誤404.但我知道的網址是好的,因爲我可以張貼到它沒有問題,使用郵遞員和發送json在身體 – firecasey