我有一个邮递员收藏,上面有多个部分,可以上传文件。
如果我在Postman中运行postman请求,则文件将上传到服务器。但是,如果我想使用newman运行它,则不会发送文件。
这是我正在运行的文件夹和命令:
laptop:/tmp/teste$ ls -ls
total 24
4 -rw-r--r-- 1 root root 595 Sep 20 13:24 localhost_environment.json
4 -rwxr-xr-x 1 root root 5 Sep 20 13:56 example.xml
4 -rw-r--r-- 1 root root 4026 Sep 20 14:34 test.json
laptop:/tmp/teste$ newman run test.json -e localhost_environment.json --disable-unicode --reporters cli
如您所见,我将example.xml(在test.json中引用的上传文件)放在同一路径中。您可以在此处看到文件test.json:
"collection": {
"info": {
"_postman_id": "9ab35d88-d65b-445e-acd3-e125b64c804d",
"name": "Tests REST API",
"description": "Tests REST API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Reports",
"item": [
{
"name": "ImportFile",
"item": [
{
"name": "Import First File",
"_postman_id": "7a8435e1-7bfe-459b-8c6e-5d008ebb81f9",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "name",
"value": "TestFile",
"type": "text"
},
{
"key": "description",
"value": "Lets hope this works",
"type": "text"
},
{
"key": "file",
"type": "file",
"src": "example.xml"
}
]
},
"url": {
"raw": "{{apiBaseUrl}}/uploadFile",
"host": [
"{{apiBaseUrl}}"
],
"path": [
"uploadFile"
]
}
},
"response": []
}
],
"_postman_id": "1903ad95-7a76-49b1-9910-2bb2594c24e5",
"_postman_isSubFolder": true
}
],
"_postman_id": "6629c985-633b-440d-aaf6-6ceb6cef45bb"
}
],
"variable": [
{
"id": "01c84c7d-1b4a-4335-869c-69f404d0ba5a",
"key": "adminUsername",
"value": "*******",
"type": "string"
},
{
"id": "674e3cb7-16c6-4c60-ba81-5c8856eb4eab",
"key": "adminPassword",
"value": "******",
"type": "string"
},
{
"id": "c1ab7891-cd42-43c0-860d-239513199e2b",
"key": "apiBaseUrl",
"value": "http://localhost:8081/rest",
"type": "string"
}
]
}
}
这是正在生成的请求:
{
"id": "7a8435e1-7bfe-459b-8c6e-5d008ebb81f9",
"name": "Import First File",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"user-agent": "PostmanRuntime/7.16.2",
"accept": "*/*",
"cache-control": "no-cache",
"postman-token": "ff66e4d2-2ed3-4662-88ea-0baaab7b017f",
"host": "localhost:8081",
"accept-encoding": "gzip, deflate",
"cookie": "JSESSIONID=DF9E3EE6D9263FFE1AEC26F53AB4297B",
"content-length": 511,
"connection": "keep-alive"
},
"method": "POST",
"url": "http://localhost:8081/rest/uploadFile",
"data": {
"name": "TestFile",
"description": "Lets hope this works",
"file": {
"_readableState": {
"objectMode": false,
"highWaterMark": 65536,
"buffer": {
"head": null,
"tail": null,
"length": 0
},
"length": 0,
"pipes": null,
"pipesCount": 0,
"flowing": true,
"ended": true,
"endEmitted": true,
"reading": false,
"sync": false,
"needReadable": false,
"emittedReadable": false,
"readableListening": false,
"resumeScheduled": false,
"paused": false,
"emitClose": false,
"autoDestroy": false,
"destroyed": true,
"defaultEncoding": "utf8",
"awaitDrain": 0,
"readingMore": false,
"decoder": null,
"encoding": null
},
"readable": false,
"_events": {},
"_eventsCount": 3,
"path": "/tmp/teste/example.xml",
"fd": null,
"flags": "r",
"mode": 438,
"end": null,
"autoClose": true,
"bytesRead": 5,
"closed": true
}
}
}
但是文件未发送到服务器。有人会遇到相同的行为吗?
预先感谢