简体   繁体   English

将带有附加参数的curl转换为PHP curl

[英]Convert curl with additional parameters into PHP curl

Trying to convert a curl command for building Jenkins job so I can use it in PHP. 尝试转换curl命令以构建Jenkins job以便可以在PHP中使用它。 Here is what I do: 这是我的工作:

<?php

        $testrun_id = "1744";
        $cmd="curl -X POST http://build:f9280f220bfb4c596f83a0@mobile-jenkins.me.com:8080/job/android-job-git/build --data-urlencode json='{"parameter": [{"name":"POST_RESULTS", "value":"true"}, {"name":"RUN_ID", "value":"{$testrun_id}"}, {"name":"CHECK_NAME", "value":"SampleAutomatedPlan"}]}'";
        exec($cmd, $result);

?>

Here I am passing 3 parameters to the jenkins job and they are POST_RESULTS with value true , RUN_ID with value of var $testrun_id which is 1744 and CHECK_NAME whose value is SamplAutomatedPlan . 在这里,我传递3个参数的jenkins job ,他们是POST_RESULTS值为trueRUN_ID使用var价值$testrun_id这是1744CHECK_NAME ,其值是SamplAutomatedPlan When I run this curl command on mac terminal, it works perfectly fine. 当我在Mac终端上运行curl命令时,它的工作原理非常好。

What would be the missing things OR errors that gives me Parse error: parse error on that $cmd="curl..." line when I try to run this php script? 当我尝试运行此php脚本时,缺少的东西或给我Parse error: parse error on that $cmd="curl..." line

您需要通过添加反斜杠来转义双引号。

$cmd = "curl -X POST http://build:f9280f220bfb4c596f83a0@mobile-jenkins.me.com:8080/job/android-job-git/build --data-urlencode  json='{\"parameter\": [{\"name\":\"POST_RESULTS\", \"value\":\"true\"}, {\"name\":\"RUN_ID\", \"value\":\"{$testrun_id}\"}, {\"name\":\"CHECK_NAME\", \"value\":\"SampleAutomatedPlan\"}]}'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM