运行带有节点的发布请求,添加选项参数和标头,获取pointernullexception

时间:2019-03-08 21:10:06

标签: javascript node.js api server backend

这是server.js中的代码

const https = require('https')
const http = require("http");
const fs = require('fs');

const fileUrl = new URL('file:///Users/someone.computer/Desktop/sampleFile.csv');

const post_data = fs.readFileSync(fileUrl);

const options = {
  host: 'api.thomsonreuters.com',
  // port: 443,
  path: '/permid/match/file',
  method: 'POST',
  headers: {
    'x-ag-access-token': 'myToken',
    'x-openmatch-numberOfMatchesPerRecord': 1,
    'x-openmatch-dataType': 'Organization',
    'Content-Type': 'multipart/form-data'
  }
}

const req = https.request(options, (res) => {
  var str = '';
  console.log(res)
  console.log(`statusCode: ${res.statusCode}`)
  res.on('data', function (chunk) {
    str += chunk;
    console.log("this is chunk = " + chunk)
  });
  res.on("end", function () {
    console.log("this is str = " + str)
  })
})

req.write(post_data);
req.end();

我需要使用csv文件并通过permid.org运行它,并使用其API文件匹配功能匹配包含要匹配数据的本地csv文件。在他们的docs中,它说我需要包括参数和标头,就像我在下面称为options的对象中包含的一样。要读取我正在使用的文件fs npm package

当我运行node server.js时,我进入终端机

statusCode: 500
this is chunk = {"error": {"status": {
    "code": "500",
    "errorCode": "Server Error",
    "errorDescription": "java.lang.NullPointerException"
}}}
this is str = {"error": {"status": {
    "code": "500",
    "errorCode": "Server Error",
    "errorDescription": "java.lang.NullPointerException"
}}}

请告知我我在做什么错-预先感谢!

0 个答案:

没有答案