gpt4 book ai didi

node.js - 类型错误 : Request path contains unescaped characters NodeJS + Dynamics

转载 作者:太空宇宙 更新时间:2023-11-03 21:52:30 31 4
gpt4 key购买 nike

我正在向 Dynamics CRM 发出 https.request,以获取 Node js 中联系人的数据。

下面是我的代码:

var options = { path: '/api/data/v8.2/contacts?$select=address1_city,address1_line1,address1_line2,address1_line3,contactid,emailaddress1,firstname,fullname,middlename,mobilephone,statecode,suffix,telephone1,vcm_npiid,vcm_prescriberspeciality,vcm_prescriberstatus,vcm_recordtype,vcm_symphonyid&$orderby=fullname asc&$filter=statecode eq 0',
host: 'xxxxxx.crm.dynamics.com',
method: 'GET',
headers:
{ Authorization: 'Bearer xxxxxxx',
Accept: 'application/json',
'Content-Type': 'application/json; charset=utf-8',
Prefer: 'odata.includeannotations=OData.Community.Display.V1.FormattedValue',
'OData-MaxVersion': '4.0',
'OData-Version': '4.0'
}
}

var crmrequest = https.request(options, function(response) { ... }

我收到此错误:

TypeError: Request path contains unescaped characters

当我尝试在 asc 和 eq 0 查询之间没有空格时[通过删除它]。有用。任何解决方法

最佳答案

您必须使用querystring.stringifyencodeURI为了转义特殊字符。

const querystring = require('querystring');
const path = '/api/data/v8.2/contacts';
const qs = {
$select: 'address1_city,address1_line1,address1_line2,address1_line3,contactid,emailaddress1,firstname,fullname,middlename,mobilephone,statecode,suffix,telephone1,vcm_npiid,vcm_prescriberspeciality,vcm_prescriberstatus,vcm_recordtype,vcm_symphonyid',
$orderby: 'fullname asc',
$filter: 'statecode eq 0'
}

const options = {
path: path + '?' + querystring.stringify(qs),
host: 'xxxxxx.crm.dynamics.com',
method: 'GET'
/* ... */
}
<小时/>
const path = '/api/data/v8.2/contacts';
const query ='$select=address1_city,address1_line1,address1_line2,address1_line3,contactid,emailaddress1,firstname,fullname,middlename,mobilephone,statecode,suffix,telephone1,vcm_npiid,vcm_prescriberspeciality,vcm_prescriberstatus,vcm_recordtype,vcm_symphonyid&$orderby=fullname asc&$filter=statecode eq 0';


const options = {
path: path + '?' + encodeURI(query),
host: 'xxxxxx.crm.dynamics.com',
method: 'GET'
/* ... */
}

关于node.js - 类型错误 : Request path contains unescaped characters NodeJS + Dynamics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49886618/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com