删除换行符窗体多窗体数据。节点

时间:2019-07-02 08:55:22

标签: node.js rest

Node通过Mac发送的数据。失败:

POST / HTTP/1.1
Accept: application/json, text/plain, */*
Content-Type: multipart/form-data; boundary=--------------------------410170969577572462482590
Authorization: Basic U3dlY2q9DdlRvQ29uqdGFjdDpVM2RsWTI5RGRsUnZqRMjl1ZEdGamRB
User-Agent: axios/0.18.0
Content-Length: 437
Host: localhost:3000
Connection: close

    {
  "_overheadLength": 105,
  "_valueLength": 5,
  "_valuesToMeasure": {},
  "writable": false,
  "readable": true,
  "dataSize": 0,
  "maxDataSize": 2097152,
  "pauseStreams": true,
  "_released": false,
  "_streams": {
    "0": "----------------------------097921969493700670690484\r\nContent-Disposition: form-data; name=\"Domain\"\r\n\r\n",
    "1": "Test"
  },
  "_currentStream": {},
  "_insideLoop": false,
  "_pendingNext": false,
  "_boundary": "--------------------------097921969493700670690484"
}

从Windows从Postman发送的数据。这有效:

POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=--------------------------214255515908701131866697
Authorization: Basic U3dlY29DwerdlRvQ29uwerdGFjdDpVM2RsWTwerI5RGRsUnZRMjl1ZEdGamRB
User-Agent: PostmanRuntime/7.15.0
Accept: */*
Cache-Control: no-cache
Postman-Token: 4af4ff14-1abd-4ab7-9e01-5ddd846acfa9
Host: localhost:3020
accept-encoding: gzip, deflate
content-length: 383
Connection: keep-alive

----------------------------214255515908701131866697
Content-Disposition: form-data; name="Domain"

test
--

似乎该节点在这里和那里添加行制动器:\r\n\r\n

当我向其中发布数据时,这会导致Windows服务器出现故障:“超出了行长100”。

看到这个问题:Sending post request multipart form data. Error from some microsoft service "Line length limit 100 exceeded"

我正在使用这个form-data包来发布与axios结合的数据。

是否可以添加一些过滤器/中间件等来删除我的帖子请求中的alla / n / r等?

更新

我从节点的请求:

const form_data = new FormData();
form_data.append('Domain', 'test');


const request_config = {
        headers: {
            "Authorization": "Basic dffdg",
            "Content-Type": `multipart/form-data; boundary=${form_data._boundary}`
        },
        data: form_data
    };


    await axios.post(url, form_data, request_config).then(response => {

1 个答案:

答案 0 :(得分:1)

尝试从data中删除request_config

const form_data = new FormData();
form_data.append('Domain', 'test');


const request_config = {
    headers: {
        "Authorization": "Basic dffdg",
        "Content-Type": `multipart/form-data; boundary=${form_data._boundary}`
    },
    //data: form_data
};


await axios.post(url, form_data, request_config).then( /* ... */ )

摘自axios/axios文档

  

注意

     

使用别名方法 url 方法 data 属性时,无需在配置中指定。