dran0703 2017-01-04 08:48
浏览 323
已采纳

PHP cURL Put,没有权限(403禁止)

I made a script that uses the Mobile.de API. It worked fine on their test environment, only difference with the live environment is the proxy. So in my cURL I removed the proxy. For any POST call this works just fine, but for my PUT call it doesn't work at all.

So let's say I sent the following with for example Postman:

PUT /seller-api/sellers/123/ads/456
Host: services.mobile.de
Content-Type: application/vnd.de.mobile.api+json
Authorization: Basic abcdef12345=

And I put in the right JSON, it works just fine.
And this is the script I use in PHP:

function updateVehicle($seller, $voertuig_id, $json) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://services.mobile.de/seller-api/sellers/' . $seller . '/ads/' . $voertuig_id);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_USERPWD, USERNAME . ':' . PASSWORD);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Host: services.mobile.de',
        'Content-type: application/vnd.de.mobile.api+json'
    ));

    $output = curl_exec($ch);

    curl_close($ch);

    return $output;
}

In return I get the 403 forbidden. 'You don't have permission to access /seller-api/sellers/123/ads/456 on this server.'

I already printed out al curl info and saw that all the headers are there and everything seems just fine, but why don't I have permission.

Contacted Mobile.de already but they say it's something in my code.

  • 写回答

1条回答 默认 最新

  • doupu0619 2017-01-04 14:30
    关注

    So after much debugging I found out it was a space after the $voertuig_id that got me an 403 forbidden error. :S

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器