curl - curl:以称为文件的多部分形式发布一个字段?
问题描述
我想替换这个:
curl -F 'file=@a.html' http://localhost:8080/convert
和
curl -F 'file=<html><body>Inline!</body></html>' http://localhost:8080/convert
但这只是让我:curl: (26) couldn't open file "html><body>a</body></html>"
使用 curl -d 不起作用(大概是因为它不会生成多部分主体?)
如何在 curl 参数中嵌入内容,而不是依赖对实际文件的引用?
解决方案
使用--form-string
参数而不是 -F,例如
curl --form-string 'file=<html><body>Inline!</body></html>' http://localhost:8080/convert
产生
POST /convert HTTP/1.1
Host: localhost:8080
User-Agent: curl/7.59.0
Accept: */*
Content-Length: 172
Content-Type: multipart/form-data; boundary=------------------------2e4ba7fc50e9eec8
--------------------------2e4ba7fc50e9eec8
Content-Disposition: form-data; name="file"
<html><body>Inline!</body></html>
--------------------------2e4ba7fc50e9eec8--
推荐阅读
- image - 如何计算k-means聚类中两点之间的颜色距离?
- sitefinity - 更新到开发服务器时,sitefinity 自定义小部件未显示任何内容
- python - 访问列表列表中列表的第一个元素
- fluentui-react - 不使用 TypeScript 时无法导入 IDropdownOption
- anylogic - 当资源空闲时为资源创建任务列表的方法
- c++ - 使用 stb_image.h 读取 PNG 会导致内存充满 NUL 字节
- c++ - 隐藏 std::function 的参数类型
- python - IndexError:在for循环上迭代字符串并按索引放置字符
- swift - 为什么我可以将 [UInt8] 类型传递给 UnsafePointer
类型参数? - foreach - Terraform 14.2:“错误:无效索引:该值没有任何索引”在销毁时间资源上的销毁时间供应商上