有多个参数的卷毛岗位

时间:2014-04-11 10:01:28

标签: php curl

我需要在php中为此命令执行Post curl:

curl -k -X POST https://openshift.redhat.com/broker/rest/domains/did/applications/test/events 
--user "[UserName]:[Password]" --data "event=restart""

我尝试但是它没有工作:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://openshift.redhat.com/broker/rest/domains/did/applications/test/events");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "--user "[UserName]:[Password]" --data "event=restart" ");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

我应该得到-K和-X,所以任何想法如何做到这一点?

1 个答案:

答案 0 :(得分:1)

有关可用选项,请参阅curl_setopt

<?php
$username = 'username';
$password = 'password';
$url = 'https://example.com/';
$cookie = 'cookie.txt';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'event=restart');
curl_setopt($ch, CURLOPT_POST, true);

$response = curl_exec($ch);

curl_close($ch);
?>