首页 > 解决方案 > cURL:HTTP/2 流 1 未完全关闭:PROTOCOL_ERROR (err 1)

问题描述

我正在尝试通过 cURL 将视频上传到 Youtube 的 API。这是我的代码:

curl -v -X PUT '#{upload_uri}' -H 'Authorization: Bearer #{@test_token}' -H 'Content-Length: #{File.size(@video).to_s}' -H 'Content-Type: video/*' -d @'#{@video}'

我收到的回复是

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 216.58.196.170...
* TCP_NODELAY set
* Connected to www.googleapis.com (216.58.196.170) port 443 (#0)
---
---
* Using Stream ID: 1 (easy handle 0x7f9570000400)
> PUT /upload/youtube/v3/videos?part=snippet,status,contentDetails&uploadType=resumable&upload_id=<id> HTTP/2
> Host: www.googleapis.com
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: Bearer <token>
> Content-Length: 140926828
> Content-Type: video/*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
} [16384 bytes data]
 97 65.3M    0     0   97 64.0M      0  3704k  0:00:18  0:00:17  0:00:01 4226k* We are completely uploaded and fine
< HTTP/2 400 
< content-type: text/html; charset=UTF-8
< referrer-policy: no-referrer
< content-length: 1555
< date: Wed, 04 Mar 2020 09:21:34 GMT
< 
* HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)
 99 65.3M    0     0  100 65.3M      0  3714k  0:00:18  0:00:18 --:--:-- 4242k
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
} [2 bytes data]
curl: (92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)

我知道这与不正确的值有关Content-Length。但是,此标头的值与作为二进制发送的文件的大小相匹配。

那么在 cURL 中是什么导致了这个错误呢?

此请求与邮递员完美配合,Content-Length此处提供的相同。

标签: curlvideoyoutube

解决方案


推荐阅读