【发布时间】:2015-06-25 21:48:20
【问题描述】:
我想从命令行执行一个具有多部分/混合边界的相当复杂的 HTTP 请求。
POST /batch HTTP/1.1
Host: www.googleapis.com
Content-length: 592
Content-type: multipart/mixed; boundary=batch_0123456789
Authorization: Bearer authorization_token
--batch_0123456789
Content-Type: application/http
Content-ID: <item1:user@example.com>
Content-Transfer-Encoding: binary
POST /drive/v2/files/fileId/permissions
Content-Type: application/json
Content-Length: 71
{
"role": "reader",
"type": "user",
"value": "user@example.com"
}
--batch_0123456789
Content-Type: application/http
Content-ID: <item2:user@example.com>
Content-Transfer-Encoding: binary
POST /drive/v2/files/fileId/permissions
Content-Type: application/json
Content-Length: 71
{
"role": "reader",
"type": "user",
"value": "user@example.com"
}
--batch_0123456789--
理想情况下,我想将此请求放入一个文件中,然后简单地调用 curl 来执行该 HTTP 请求。
curl myrequest.txt
有什么简单直接的方法吗?我知道有些客户端库有其惯用的处理方式,但我很想知道是否有办法从命令行执行此操作。
【问题讨论】: