【发布时间】:2017-10-21 22:51:40
【问题描述】:
我正在尝试对 NodeJS 中的批量地理编码执行发布请求。 我正在使用请求库,但由于需要将发布数据作为多行列纯文本数据发送,因此请求失败。
示例帖子数据(使用列分隔符“|”):
recId|searchText|country
0001|Invalidenstraße 116 10115
这是我的要求:
requestPromise.post({
uri: 'https://batch.geocoder.cit.api.here.com/6.2/jobs',
qs: {
app_id: {APP ID}
, app_code: {APP CODE}
, action: 'run'
, mailto: {EMAIL}
, gen: 8
, header: true
, ndelim: '%7C'
, outdelim: '%7C'
, outcols: 'displayLatitude,displayLongitude,locationLabel,houseNumber,street,district,city,postalCode,county,state,country'
, outputCombined: false
},
body:'recId|searchText|country\r\n0001|Invalidenstraße 116 10115 Berlin|DEU',
headers: {
'Content-Type':'text/plain',
}
注意这部分,我尝试使用换行符(\r\n):
body:'recId|searchText|country\r\n0001|Invalidenstraße 116 10115 Berlin|DEU'
但我收到此错误消息:
检测到无效的输入标头:[recId|searchText|country]。请修正输入或检查输入分隔符设置。
【问题讨论】:
-
使用反引号(字符串模板/文字)而不是单引号,删除
\r\n并在此时按回车键
标签: node.js rest http-post here-api