I have a curl request, which I can send from the cli like this:
curl -X 'PUT' \
'https://XXX/endpiontY' \
-H 'Authorization: Bearer <TOKEN>' \
-H 'Content-Type: application/json' \
-d '{
"value": "TestValue"
}'
(curl --version
returns curl 7.81.0
, so default is CURL_HTTP_VERSION_2TLS
)
I am trying to send the same information with PHP, but I get
HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
My Setup
$json = array('value' => 'TestValue');
$json_string = json_encode($json);
$headers = array(
'Content-Type:application/json',
'Content-Length: ' . strlen($json_string)
)
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_string);
curl_setopt($ch, CURLOPT_PUT, true);
$result = curl_exec($ch);
if ($result === false) {
$error = curl_error($ch);
}
curl_close($ch);
$result
is always false
so the error triggers with the above message shown.
I tried
I found this https://stackoverflow.com/a/59955444/1092632
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- causes a timeout of the endpoint
Using
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
instead ofcurl_setopt($ch, CURLOPT_PUT, true);
- no change
Adding
$headers[] = 'Connection: close';
- no change
Where am I wrong sending the PUT request? Any hint highly appreciated!