Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将此wget函数转换为php? wget-d--header=“内容类型:应用程序/xml”--post data=“$(cat)”http://sample.sample.com/api_Php_Xml_Linux_Wget - Fatal编程技术网

如何将此wget函数转换为php? wget-d--header=“内容类型:应用程序/xml”--post data=“$(cat)”http://sample.sample.com/api

如何将此wget函数转换为php? wget-d--header=“内容类型:应用程序/xml”--post data=“$(cat)”http://sample.sample.com/api,php,xml,linux,wget,Php,Xml,Linux,Wget,如何在php中使用此函数? 我还想从这个函数中得到响应。 我在php中有一个变量,它是这样的 wget -d --header="Content-Type:application/xml" --post-data="$(cat <your xml file>)" http://sample.sample.com/api $xml='1!' ' 这就是我想发布的xml 我尝试了以下方法: $xml = '<sample> <Request target="

如何在php中使用此函数? 我还想从这个函数中得到响应。 我在php中有一个变量,它是这样的

wget -d --header="Content-Type:application/xml" --post-data="$(cat <your xml file>)" http://sample.sample.com/api
$xml='1!'
'
这就是我想发布的xml

我尝试了以下方法:

$xml = '<sample>
    <Request target="test">
    </Request>
</sample>'
$url='sample.sample.com/api';;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,“$(cat)”);//接收服务器响应。。。
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
echo$server\u output=curl\u exec($ch);
卷曲关闭($ch);
但它返回了这个错误:


解析XML失败:需要开始标记,“您应该能够遵循类似的场景,如中所示。该站点的第二部分(发送XML)使用curl来处理此操作,该操作与wget具有类似的属性,但使用PHP库,而不是命令行二进制文件和参数。为了长寿,我将包括这个网站上的片段

$url = 'sample.sample.com/api';;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$(cat <".$xml.">)"); // receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo $server_output = curl_exec ($ch);
curl_close ($ch);

我想是的

<?php
  /*
   * XML Sender/Client.
   */
  // Get our XML. You can declare it here or even load a file.
  $xml_builder = '
                  <?xml version="1.0" encoding="utf-8"?>
                  <Test>
                      <String>I like Bharath.co.uk!</String>
                  </Test>
                 ';
  // We send XML via CURL using POST with a http header of text/xml.
  $ch = curl_init('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  curl_setopt($ch, CURLOPT_REFERER, 'http://www.bharath..co.uk');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $ch_result = curl_exec($ch);
  curl_close($ch);
  // Print CURL result.
  echo $ch_result;
?>
$cmd=“wget-d--header=\”内容类型:application/xml\”--post data=\“$(cat)\”http://sample.sample.com/api";
行政人员($cmd);
$outputfile=“dl.html”;
回显文件\u获取\u内容($outputfile);

您尝试过php curl对象吗?我不知道如何使用curl来实现类似wget函数的功能。。。如果你知道如何让curl像这样工作,这将是这个问题的巨大复制:阅读@Aviv,请将代码作为对原始问题的编辑发布。通过这种方式,它的格式便于查看。有更多的系统效率的方法来实现这一点。Curl是正确的工具;然后运行脚本,它永远不会完成加载,但是如果我将其更改为$ch=curl_init();它运行,但我没有得到任何响应。使用curl_init,它会将CURLOPT_URL设置为传递给函数的值。所以你试试看,
$cmd = "wget -d --header=\"Content-Type:application/xml\" --post-data=\"$(cat <your xml file>)\" http://sample.sample.com/api";
exec($cmd);
$outputfile = "dl.html";
echo file_get_contents($outputfile);