axios 中的转义
Escape " in axios
我正在 api 调用 WuFoo 表单
要执行 dateCreated 过滤器,它需要如下所示(注意双引号):
Filter1=DateCreated+Is_greater_than+"2019-11-13 12:00:00"
但是,Axios 将其 urlencode 为如下所示:
Filter1=DateCreated%2BIs_greater_than%2B%222019-11-13+12:00:00%22'
不幸的是,WuFoo returns 对此做出了错误的回应。
我已经尝试使用 paramSerializer 退出 aping 编码:
const instance = axios.create({
baseURL: 'https://subdomain.wufoo.com/api/v3',
timeout: 1000,
headers: { 'Authorization': 'Basic fjdkalfjkdafldklaskflsdkl' },
paramsSerializer: function(params) { return params }
});
.....
instance.get('/forms/form/entries.json',{
params:{
Filter1: qDateFilter
}
})
qDateFilter = DateCreated+Is_greater_than+"2019-11-13 12:00:00"
但是我现在有以下错误:
TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
at new ClientRequest (_http_client.js:139:13)
at Object.request (https.js:309:10)
at RedirectableRequest._performRequest (/home/node/app/node_modules/follow-redirects/index.js:169:24)
at new RedirectableRequest (/home/node/app/node_modules/follow-redirects/index.js:66:8)
at Object.wrappedProtocol.request (/home/node/app/node_modules/follow-redirects/index.js:307:14)
at dispatchHttpRequest (/home/node/app/node_modules/axios/lib/adapters/http.js:180:25)
at new Promise (<anonymous>)
at httpAdapter (/home/node/app/node_modules/axios/lib/adapters/http.js:20:10)
at dispatchRequest (/home/node/app/node_modules/axios/lib/core/dispatchRequest.js:59:10)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
code: 'ERR_UNESCAPED_CHARACTERS'
}
尝试只使用完整的字符串作为 URL 也不起作用,它仍然对其进行编码。
在 postman 中直接使用 " 效果很好,与 curl 相同。
还有其他选择吗?
WuFoo 回复了我。这不是 " 它实际上是 + 号的编码。我用空格替换它并且有效。
我正在 api 调用 WuFoo 表单
要执行 dateCreated 过滤器,它需要如下所示(注意双引号):
Filter1=DateCreated+Is_greater_than+"2019-11-13 12:00:00"
但是,Axios 将其 urlencode 为如下所示:
Filter1=DateCreated%2BIs_greater_than%2B%222019-11-13+12:00:00%22'
不幸的是,WuFoo returns 对此做出了错误的回应。
我已经尝试使用 paramSerializer 退出 aping 编码:
const instance = axios.create({
baseURL: 'https://subdomain.wufoo.com/api/v3',
timeout: 1000,
headers: { 'Authorization': 'Basic fjdkalfjkdafldklaskflsdkl' },
paramsSerializer: function(params) { return params }
});
.....
instance.get('/forms/form/entries.json',{
params:{
Filter1: qDateFilter
}
})
qDateFilter = DateCreated+Is_greater_than+"2019-11-13 12:00:00"
但是我现在有以下错误:
TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
at new ClientRequest (_http_client.js:139:13)
at Object.request (https.js:309:10)
at RedirectableRequest._performRequest (/home/node/app/node_modules/follow-redirects/index.js:169:24)
at new RedirectableRequest (/home/node/app/node_modules/follow-redirects/index.js:66:8)
at Object.wrappedProtocol.request (/home/node/app/node_modules/follow-redirects/index.js:307:14)
at dispatchHttpRequest (/home/node/app/node_modules/axios/lib/adapters/http.js:180:25)
at new Promise (<anonymous>)
at httpAdapter (/home/node/app/node_modules/axios/lib/adapters/http.js:20:10)
at dispatchRequest (/home/node/app/node_modules/axios/lib/core/dispatchRequest.js:59:10)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
code: 'ERR_UNESCAPED_CHARACTERS'
}
尝试只使用完整的字符串作为 URL 也不起作用,它仍然对其进行编码。
在 postman 中直接使用 " 效果很好,与 curl 相同。
还有其他选择吗?
WuFoo 回复了我。这不是 " 它实际上是 + 号的编码。我用空格替换它并且有效。