0

I use the nodejs to execute the curl request post error.

I thought it was a single quote. I changed all the single quotes to double quotes, but it still didn't work.

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();

})

Error message:

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"}
Mehdi
  • 7,204
  • 1
  • 32
  • 44
  • Welcove to Stack Overflow. Why do you want to use `curl` , rather than node.js built-in `http` library, or perhaps `request` module? See also https://stackoverflow.com/questions/6158933/how-is-an-http-post-request-made-in-node-js – Mehdi May 16 '19 at 10:48
  • The escapes are not consistent, each double-quote sign should be escaped: `\"ownerApp":"string"` should be `\"ownerApp\":\"string\"`... – Mehdi May 16 '19 at 10:49
  • @Mehdi Because it is to realize the function of calling the Conductor, the engineer who deployed the Conductor let me use the curl to carried out – tclzzhang May 16 '19 at 10:54
  • @Mehdi I added \ to the front of the double quotes, but I still get the above error. – tclzzhang May 16 '19 at 11:15
  • Possible duplicate of [How to send double quote in -d parameter for curl.exe?](https://stackoverflow.com/questions/4514199/how-to-send-double-quote-in-d-parameter-for-curl-exe) – Mehdi May 16 '19 at 14:07
  • Please edit the question with the adapted version of the code with `\` characters. – Mehdi May 16 '19 at 14:08
  • `curl` or a `POST` `http` request sent directly with `node` should have the same effect on the server. – Mehdi May 16 '19 at 14:08
  • @Mehdi Thank you very much, I am now adjusting to such ""ownerApp"":""string"", which can be executed normally. – tclzzhang May 17 '19 at 02:41

0 Answers0