从多表单数据中删除换行符.节点 [英] Remove line breaks form mult form data. Node
问题描述
通过 Mac 从 Node 发送的数据.这失败了:
Data sent from Node via Mac. This fails:
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 发送的数据.这有效:
Data sent from Postman from Windows. This works:
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
在这里和那里.
It seem's node add row brakes: \r\n\r\n
here and there.
当我向 Windows 服务器发送数据时,这会导致它发生故障:超过了 100 行长度".
This causes a failure from a windows server when I post data to it: "Line length 100 exceeded".
看这个问题:发送发布请求多部分表单数据.来自某些微软服务的错误超过了 100 行长度限制"
我正在使用这个 form-data 包来发布与 axios 结合的数据.
I'm using this the form-data package to post data combined with axios.
是否可以在我的帖子请求中添加一些过滤器/中间件等来删除 alla/n/r 等?
Is it possible to add some filter/middleware etc that removes alla /n/r etc in my post request?
更新
我来自节点的请求:
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 => {
推荐答案
尝试从 request_config
中删除 data
.
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、method 和 data 属性不需要在配置中指定.
When using the alias methods url, method, and data properties don't need to be specified in config.
这篇关于从多表单数据中删除换行符.节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!