使用node.js执行curl以使发布请求错误

时间:2019-05-16 10:42:25

标签: node.js curl

我使用nodejs执行curl请求发布错误。

我以为是单引号。我将所有单引号更改为双引号,但仍然无法正常工作。

router.get('/getCon',(req,res)=>{
    const util = require('util');
    const exec = util.promisify(require('child_process').exec);

    async function lsExample() {
    var cmdStr1='curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{\"ownerApp":"string",\"createTime":0,\"updateTime":0,\"createdBy":"string",\"updatedBy":"string",\"name":"string",\"description":"string",\"version":2,\"tasks":[\{\"name":"string",\"taskReferenceName":"string",\"description":"string",\"inputParameters":{},\"type":"string",\"dynamicTaskNameParam":"string",\"caseValueParam":"string",\"caseExpression":"string",\"decisionCases":{},\"dynamicForkJoinTasksParam":"string",\"dynamicForkTasksParam":"string",\"dynamicForkTasksInputParamName":"string",\"defaultCase":[\{}\],\"forkTasks":[\[\{}\]\],\"startDelay":0,\"subWorkflowParam":{\"name":"string",\"version":0\},\"joinOn":[\"string"\],\"sink":"string",\"optional":false,\"taskDefinition":{\"ownerApp":"string",\"createTime":0,\"updateTime":0,\"createdBy":"string",\"updatedBy":"string",\"name":"string",\"description":"string",\"retryCount":0,\"timeoutSeconds":0,\"inputKeys":[\"string"\],\"outputKeys":[\"string"\],\"timeoutPolicy":"RETRY",\"retryLogic":"FIXED",\"retryDelaySeconds":0,\"responseTimeoutSeconds":0,\"concurrentExecLimit":0,\"inputTemplate":{},\"rateLimitPerFrequency":0,\"rateLimitFrequencyInSeconds":0\},\"rateLimited":false\}\],\"inputParameters":[\"string"\],\"outputParameters":{},\"failureWorkflow":"string",\"schemaVersion":0,\"restartable":false,\"workflowStatusListenerEnabled":false\}" http://localhost:8080/api/metadata/workflow'

    const { stdout, stderr } = await exec(cmdStr1);
    console.log('stdout:', stdout);
    console.log('stderr:', stderr);
    return res.json({'data':stdout})
    }
    lsExample();

})

错误信息:

stdout: {"code":"INTERNAL_ERROR","message":"INTERNAL_ERROR - Unexpected character ('o' (code 111)): was expecting double-quote to start field name\n at [Source: HttpInputOverHTTP@304473c1[c=1059,s=STREtOverHTTP@304473c1[c=1059,s=STREAM]; line: 1, column: 3]","retryable":false,"instance":"localhost"}

0 个答案:

没有答案