doupao6698 2016-01-04 10:42
浏览 232

在GET方法中使用curl发送数据时出错

I have to send my data in json format via a curl to create a new merchant application.I got mail from my support team.

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;

But I got "HTTP Status 405 - Request method 'GET' not supported".

Please tell me my mistake in curl because as mention in mail i have to use X GET and I am using only GET.

  • 写回答

2条回答 默认 最新

  • dqmfo84644 2016-01-04 10:59
    关注

    It's unlikely for /merchant/create to be accepting GET method and since it says PUT in the request, you should try with PUT even though the more obvious option would be to try with POST (and use PUT for updating).

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大