【问题标题】:curl commandline to phpcurl命令行到php
【发布时间】:2013-01-11 19:07:46
【问题描述】:

我有一个命令在转换为 php 时遇到问题。

curl -i -X POST -u user:userpass --url http://cloud.netelignet.ca/virtual_machines/:virtual_machine_id/startup.xml

【问题讨论】:

  • 只是好奇你尝试了什么?你有一些代码要发布吗?
  • 网址中的:virtual_machine_id 是什么?

标签: php linux curl


【解决方案1】:

我认为它等同于以下内容:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://cloud.netelignet.ca/virtual_machines/:virtual_machine_id/startup.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$username = 'user'; $password = 'userpass';
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HEADER, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

【讨论】:

  • 这看起来很接近我所拥有的,除了缺少两个选项,但它仍然不起作用。也许我会尝试联系他们。
  • “不起作用”没有用。你有错误吗?你嗅探到请求了吗?
  • 我一定做错了什么。它根本没有从 echo、var_dump、print_r 获得任何输出,但我确实使用以下代码让它工作。
  • $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "cloud.netelignet.ca/virtual_machines/:virtual_machine_id/…); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERPWD, "用户名:密码"); curl_setopt($ ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/xml')) ; $output = curl_exec($ch); curl_close($ch);
猜你喜欢
  • 2013-04-18
  • 2017-06-29
  • 1970-01-01
  • 1970-01-01
  • 2012-08-29
  • 2013-08-25
  • 2015-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多