curl - 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
此处提供的相同。
解决方案
推荐阅读
- spring - Spring Boot JMS 集成期间出现“WorkManager 的重复初始化”错误
- bootstrap-4 - 是否可以更改自举表的语言?
- c - 为什么我不能在函数中声明常量?
- python - lxml 如何保留 HTML 标签结构?
- reactjs - 在多步反应形式和反应上下文中步骤重新加载后保持值
- javascript - 在 javascript 嵌套对象中,如何通过 id 之类的属性获取所有父属性链?(如果可能,vanilla javascript)
- excel - 如何防止 Excel 中意外/无意的单元格编辑?
- python - 如何将多进程更改为单进程
- python - 仅使用从长到宽的列来旋转数据框
- json - jq 获取对象列表中给定键的所有唯一值