问题与xml文件保存使用curl和php [英] problem with xml file saving using curl and php
问题描述
我使用curl和xml将我的xml发布到一个URL。
我现在得到它的响应,但它不显示在输出。当我通过右键单击XML文件输出来访问查看源代码
页面时,p>
。
我需要将该xml文档存储到一个文件中。
我使用下面的代码
< ;?
$ path =https://newport.ingrammicro.com/mustang; // $ _POST解析的文件的相对路径
$ ch = curl_init($ path); // Initialise curl resource with above file
$ data =my xml document to post;
//要发送到文件的数据
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ data); //将数据发送到文件?
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,0);
curl_setopt($ ch,CURLOPT_HEADER,0);
$ val = curl_exec($ ch);
curl_close($ ch); //关闭curl会话
$ fp = fopen('data.xml','w');
fwrite($ fp,$ val);
fclose($ fp);
?>
但是当我打开保存的文件只有一个值1 / code>这是我在文件中得到的值。
实际上是来自curl语句的真值($ val = curl_exec );)
bool(true)
i尝试回显Sval的值,它也是1
如何保存我的XML输出文件与XML文件输出完全一样。当我查看页面源代码
它将看起来像这样
< PNAResponse>
< Version> 2.0< / Version>
< TransactionHeader>
< SenderID> 14-018111< / SenderID>
< ReceiverID> 14-018111< / ReceiverID>
< ErrorStatus ErrorNumber =/>
< DocumentID> {F1B17BBB-F848-4693-914A-B6943AA9009A}< / DocumentID>
< TransactionID />
< TimeStamp> 2009-06-17T22:42:44< / TimeStamp>
< / TransactionHeader>
< PriceAndAvailability SKU =V06669Quantity =5GovtProgramType =PAGovtEndUserType =F>
< Price> 1413.04< / Price>
< SpecialPriceFlag> Y< / SpecialPriceFlag>
< ManufacturerPartNumber> V11H270020< / ManufacturerPartNumber>
< ManufacturerPartNumberOccurs />
< VendorNumber> 4913< / VendorNumber>
< Description> POWERLITE 1735W LCD PROJ< / Description>
< ReserveInventoryFlag> N< / ReserveInventoryFlag>
< AvailableRebQty> 0< / AvailableRebQty>
< Branch ID =10Name =Mira Loma,California>
< Availability> 7< / Availability>
< OnOrder> 8< / OnOrder>
< ETADate> 2009-06-19< / ETADate>
< / Branch>
< Branch ID =30Name =Millington,Tennessee>
< Availability> 0< / Availability>
< OnOrder> 4< / OnOrder>
< ETADate> 2009-06-22< / ETADate>
< / Branch>
< Branch ID =40Name =Carol Stream,Illinois>
< Availability> 0< / Availability>
< OnOrder> 18< / OnOrder>
< ETADate> 2009-06-18< / ETADate>
< / Branch>
< Branch ID =80Name =Jonestown Pennsylvania>
< Availability> 0< / Availability>
< OnOrder> 9< / OnOrder>
< ETADate> 2009-06-23< / ETADate>
< / Branch>
< / PriceAndAvailability>
< / PNAResponse>
有没有人知道如何做?
也可以尝试添加一些用户代理,以确保您获得的输出与实际浏览器相同
@curl_setopt($ ch,CURLOPT_USERAGENT,Mozilla / 5.0(Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1)Gecko / 20061204 Firefox / 2.0.0.1 );
I am using curl and xml to post my xml to a URL.
I am getting response from it right now, but its not displaying in output.
when I take the View Source
page by right clicking its there like the XML file output.
I need to store that xml document to a file.
I used this code below
<?
$path = "https://newport.ingrammicro.com/mustang"; //Relative path to the file with $_POST parsing
$ch = curl_init($path); //Initialise curl resource with above file
$data = "my xml document to post";
//Data to be sent to the file
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //Send the data to the file?
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
$val = curl_exec($ch);
curl_close($ch); //Close curl session
$fp = fopen('data.xml', 'w');
fwrite($fp, $val);
fclose($fp);
?>
but when I opened the saved file only a single value "1"
this is the value I'm getting in the file.
actually its the true value from the curl statement($val = curl_exec($ch); ) bool(true) i tried to echo the value of Sval , it also "1"
How can i save my XML output file exactly as the XML file output.when i take view page source
it will look like this
<PNAResponse>
<Version>2.0</Version>
<TransactionHeader>
<SenderID>14-018111</SenderID>
<ReceiverID>14-018111</ReceiverID>
<ErrorStatus ErrorNumber=""/>
<DocumentID>{F1B17BBB-F848-4693-914A-B6943AA9009A}</DocumentID>
<TransactionID/>
<TimeStamp>2009-06-17T22:42:44</TimeStamp>
</TransactionHeader>
<PriceAndAvailability SKU="V06669" Quantity="5" GovtProgramType="PA" GovtEndUserType="F">
<Price>1413.04</Price>
<SpecialPriceFlag>Y</SpecialPriceFlag>
<ManufacturerPartNumber>V11H270020</ManufacturerPartNumber>
<ManufacturerPartNumberOccurs/>
<VendorNumber>4913</VendorNumber>
<Description>POWERLITE 1735W LCD PROJ</Description>
<ReserveInventoryFlag>N</ReserveInventoryFlag>
<AvailableRebQty>0</AvailableRebQty>
<Branch ID="10" Name="Mira Loma, California">
<Availability>7</Availability>
<OnOrder>8</OnOrder>
<ETADate>2009-06-19</ETADate>
</Branch>
<Branch ID="30" Name="Millington, Tennessee">
<Availability>0</Availability>
<OnOrder>4</OnOrder>
<ETADate>2009-06-22</ETADate>
</Branch>
<Branch ID="40" Name="Carol Stream, Illinois">
<Availability>0</Availability>
<OnOrder>18</OnOrder>
<ETADate>2009-06-18</ETADate>
</Branch>
<Branch ID="80" Name="Jonestown Pennsylvania">
<Availability>0</Availability>
<OnOrder>9</OnOrder>
<ETADate>2009-06-23</ETADate>
</Branch>
</PriceAndAvailability>
</PNAResponse>
Does anyone have an idea how to do this?
also if you want try adding some user agent to be sure you are getting the same output as a real browser
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
这篇关于问题与xml文件保存使用curl和php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!