我必须通过 curl 以 json 格式发送我的数据来创建一个新的商家应用程序。我收到了来自我的支持团队的邮件。
curl -D- -X GET -H "Authorization: Basic Y2NhcGlAY2FyZGNvR05hOQ==" -H 'Accept: application/json' -H 'Content-type: application/json' -X PUT 'https://testapi.xyz.com/agentcenter/merchant/create' -d '{"merchant":{"firstName":"mike","lastName":"test","email":"mm@mandm.net","address":"123 test ln","city":"rock hill","state":"PA","zip":"19406","ownerDob":"19871218","ownerSsn":"123-12-1234","phone":"555-555-5555","url":"http:\/\/www.testurl.com","physicalAddress":"1234 ebenezer rd","physicalCity":"rock hill","physicalState":"PA","physicalZip":"19406","application":{"bankRouting":"036001808","bankAccount":"123456789","amexMid":null}}}'.
My line of code is:-
$ch = curl_init('https://testapi.com/merchant/create');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
但我得到“HTTP 状态 405 - 不支持请求方法 'GET'”。
请告诉我我在 curl 中的错误,因为正如邮件中提到的,我必须使用 X GET 并且我只使用 GET。