W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
紐曼支持文件上傳。為此,請(qǐng)將文件上傳到集合中指定的相對(duì)位置。例如,查看此集合:
{
"variables": [],
"info": {
"name": "file-upload",
"_postman_id": "9dbfcf22-fdf4-f328-e440-95dbd8e4cfbb",
"description": "A set of `POST` requests to upload files as form data fields",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "Form data upload",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var response = JSON.parse(responseBody).files[\"sample-file.txt\"];",
"",
"tests[\"Status code is 200\"] = responseCode.code === 200;",
"tests[\"File was uploaded correctly\"] = /^data:application\\/octet-stream;base64/.test(response);",
""
]
}
}
],
"request": {
"url": "https://postman-echo.com/post",
"method": "POST",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"enabled": true,
"src": "sample-file.txt"
}
]
},
"description": "Uploads a file as a form data field to `https://postman-echo.com/post` using a `POST` request."
},
"response": []
}
]
}
該文件sample-file.txt必須作為集合存在于當(dāng)前工作目錄中。像往常一樣運(yùn)行這個(gè)集合。
$ newman run file-upload.postman_collection.json
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: