Я пытаюсь сделать пост-запрос на открытие permID API.
URL-адрес запроса: https://api.thomsonreuters.com/permid/match/file?Content-Type=multipart%2Fform-data
Я пытался писать код с нуля, а также копировать и прошлые рабочие параметры, заголовки и значение тела из кода, созданного почтальоном.
Код, который я написал, закомментирован.
Не уверен, где я иду не так.
Спасибо.
const express = require('express')
const app = express()
const request = require('request');
const cors = require('cors');
// const http = require('http');
// const https = require('https');
const util = require('util')
// Sets an initial port. We"ll use this later in our listener
const PORT = process.env.PORT || 8080;
app.use(cors());
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200
};
// Service end-point (search)
// app.get('/upload', function (req, res) {
// var options = {
// method: 'GET',
// url: 'https://api.thomsonreuters.com/permid/match/file?Content-Type=multipart%2Fform-data',
// headers: {
// 'cache-control': 'no-cache',
// 'x-openmatch-dataType': 'Organization',
// 'x-openmatch-numberOfMatchesPerRecord': '1',
// 'x-ag-access-token': '96CT8NAgnieeuiYA2YPeNMnbPMfHu4W8'
// },
// formData: {
// file: undefined
// }
// };
// request(options, function (error, response, body) {
// if (error) throw new Error(error);
// console.log(response)
// console.log(body);
// });
// });
// function dataReturned(e) {
// console.log("Success!");
// finalRes.end(e);
// }
// const server = http.createServer(app)
// server.listen(PORT, () => {
// console.log(`app started! at port ${PORT}`);
// });
var http = require("https");
var options = {
"method": "POST",
"hostname": [
"api",
"thomsonreuters",
"com"
],
"path": [
"permid",
"match",
"file"
],
"headers": {
"content-type": "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
"x-openmatch-numberOfMatchesPerRecord": "1",
"x-openmatch-dataType": "Organization",
"cache-control": "no-cache",
"Postman-Token": "101e3dbe-96bf-4b1c-9fce-8dad5f4ff975"
}
};
var req = http.request(options, function(res) {
var chunks = [];
res.on("data", function(chunk) {
chunks.push(chunk);
});
res.on("end", function() {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.write("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
req.end();