TypeError:请求路径包含非转义字符NodeJS + Dynamics

时间:2018-04-17 20:06:33

标签: node.js https dynamics-crm node-request

我正在向Dynamics CRM发送https.request以获取节点js中联系人的数据。

以下是我的代码:

drive

我收到此错误:

  

TypeError:请求路径包含未转义字符

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

1 个答案:

答案 0 :(得分:1)

您必须使用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'
  /* ... */
}