Ошибка GET Node JS Curl - «имя схемы» не распознается как внутренняя или внешняя команда, исполняемая программа или комаJavascript

Форум по Javascript
Anonymous
Ошибка GET Node JS Curl - «имя схемы» не распознается как внутренняя или внешняя команда, исполняемая программа или кома

Сообщение Anonymous »

Я хочу вызвать Curl с помощью NodeJS с методом GET. Я хочу передать токен авторизации и параметр. Я написал свои коды, как показано ниже:
const url = 'https://external-url?table-name=LD_PRD& ... REF_SCHEMA';
const header = 'Basic XXXXXXNzI=';

const curlCommand = `curl -s GET -H "Authorization: ${header}" ${url}`;

try {

// Promisify the exec function to use it with async/await
const execPromise = util.promisify(exec);

const { stdout, stderr } = await execPromise(curlCommand);

if (stderr) {
// Curl might produce an error on stderr even if execPromise succeeds
throw new Error(`Curl stderr: ${stderr}`);
}

const data = JSON.parse(stdout);
//console.log('Success:', data);

return {
statusCode: 200,
body: JSON.stringify(data),
};

} catch (error: any) {
console.log("======== ERROR =========", error);
return {
statusCode: 500,
body: JSON.stringify({
message: 'Failed to execute curl command',
error: 'Failed to execute curl command',
}),
};
}

Но я вижу, что мой локон имеет ошибку и показывает 500:
{
"message": "Failed to execute curl command",
"error": "Failed to execute curl command"
}

В консоли вижу следующее:
'schema-name' is not recognized as an internal or external command, operable program or batch file.


Подробнее здесь: https://stackoverflow.com/questions/798 ... l-or-exter

Вернуться в «Javascript»