javascript - 如何使用浏览器获取 api 放置多部分/相关请求?
问题描述
我的 api 服务器接受multipart/related
各种 POST 请求。但是我找不到任何资源来解释如何使用浏览器获取 api 来放置一个这样的请求。几乎所有链接都告诉如何使用FormData
,但表单数据的内容类型不是multipart/related
,我寻求。我需要上传一个 JSON 以及各种附件文件。如何发出这样的获取请求?
有没有标准的方法来做到这一点,比如FormData
对象?还是我必须手动编写?
这就是我期望的输出
PUT /target/SpaghettiWithMeatballs?new_edits=false HTTP/1.1
Accept: application/json
Content-Length: 1030
Content-Type: multipart/related; boundary="864d690aeb91f25d469dec6851fb57f2"
Host: localhost:5984
User-Agent: CouchDB
--2fa48cba80d0cdba7829931fe8acce9d
Content-Type: application/json
{
"_attachments": {
"recipe.txt": {
"content_type": "text/plain",
"digest": "md5-R5CrCb6fX10Y46AqtNn0oQ==",
"follows": true,
"length": 87,
"revpos": 7
}
},
"_id": "SpaghettiWithMeatballs",
"_rev": "7-474f12eb068c717243487a9505f6123b",
"_revisions": {
"ids": [
"474f12eb068c717243487a9505f6123b",
"5949cfcd437e3ee22d2d98a26d1a83bf",
"00ecbbc54e2a171156ec345b77dfdf59",
"fc997b62794a6268f2636a4a176efcd6",
"3552c87351aadc1e4bea2461a1e8113a",
"404838bc2862ce76c6ebed046f9eb542",
"5defd9d813628cea6e98196eb0ee8594"
],
"start": 7
},
"description": "An Italian-American delicious dish",
"ingredients": [
"spaghetti",
"tomato sauce",
"meatballs",
"love"
],
"name": "Spaghetti with meatballs"
}
--2fa48cba80d0cdba7829931fe8acce9d
Content-Disposition: attachment; filename="recipe.txt"
Content-Type: text/plain
Content-Length: 87
1. Cook spaghetti
2. Cook meetballs
3. Mix them
4. Add tomato sauce
5. ...
6. PROFIT!
--2fa48cba80d0cdba7829931fe8acce9d--
解决方案
推荐阅读
- python - 如何使用 concat 或 merge 合并两个数据帧?
- mysql - 需要帮助加快查询速度 (FROM_UNIXTIME)
- java - graphics2D drawImage 不适用于 timer.schedule
- java - PSQLException:服务器请求基于密码的身份验证,但未提供密码
- python - PythonShell 消息仅在 Electron 中的 python 脚本执行结束时收到
- javascript - AJAX 返回的对象的未定义属性错误
- ansible - Ansible 失败“跳过:没有匹配的主机”与 ansible-pull
- heroku - 无法将自定义域添加到我的 heroku 应用程序
- javascript - 删除使用材质 ui 和 Reactjs 创建的列表中的任何项目
- encoding - 如何获得 RoBERTa 词嵌入?