【问题标题】:curl php post requestcurl php 发布请求
【发布时间】:2022-11-29 09:07:57
【问题描述】:

我有这个代码

POST /account/p_api/v1/account/authorization/assign HTTP/1.1
Host: exemple.com
Cookie: exemle-locale=en; 
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json
Content-Length: 17
Origin: https://exemple.com
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
Te: trailers
Connection: close

{"code":"herecode"}

我想使用 curl 和 php 来发送请求并将另一个代码添加到“herecode”

我不知道该怎么做

【问题讨论】:

  • PHP curl docs 有例子。
  • 这不是编码服务。在寻求帮助之前学习一点并尝试自己。

标签: php curl post request


【解决方案1】:

在您的浏览器中打开开发者工具
转到浏览器中的 url。
转到“网络选项卡”
右键单击“网络”选项卡中的第一个请求
选择复制=>卷曲

去https://curlconverter.com/php/
粘贴“卷曲副本”
你有你的 PHP 代码。

他们的 CURLOPT_HTTPHEADER 中有一个错误,您需要制作自己的标头数组。 标题示例:

'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8',

改成

'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',

Firefox curl 复制示例:

Chrome curl 复制示例:

粘贴到 urlconverter: 这是此页面的 curl 复制和粘贴。 curl php post request

【讨论】:

    猜你喜欢
    • 2015-12-06
    • 2017-11-21
    • 2020-04-26
    • 2020-08-14
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    相关资源
    最近更新 更多