gpt4 book ai didi

PHP CURL : HTTP/1. 1 411 长度要求

转载 作者:行者123 更新时间:2023-12-02 15:22:01 25 4
gpt4 key购买 nike

即使我指定了内容长度,我仍然收到错误:

Length Required


HTTP Error 411. The request must be chunked or have a content length.

这是我的代码

$curl = curl_init();
$data = array("Key" => "Value", "Key2" => "Value2");
$data = json_encode($data);
$length = strlen($data);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json;charset=utf-8", "Content-Length: $length"));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_HEADER, true);

$result = curl_exec($curl);

有什么想法吗?

最佳答案

您确定需要使用 NTLM 身份验证选项吗?

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);

我对此进行了测试,它导致请求中省略了 content-type header 以及 JSON 负载。

尝试删除该行并查看请求是否有效。

关于PHP CURL : HTTP/1. 1 411 长度要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35066772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com