1

我将 xml 从我的 javascript 发送到 php 服务器,

javascript在php上发送这个

------WebKitFormBoundaryFfB4YR7FJLBRkPEY
Content-Disposition: form-data; name="file"; filename="prova_Fld.xml"
Content-Type: text/xml
  <Node>
    <NodeId>001</NodeId>
    <HwVers>1</HwVers>
    <FwVers>1</FwVers>
    <MacAdrs>[00:0d:6f:00:01:8d:18:29]!</MacAdrs>
    <Notes>prova</Notes>
    <Device>
      <Address>01</Address>
      <Name>dev1</Name>
      <Function>prova device</Function>
      <Register>
        <Address>0100</Address>
        <Name>register1</Name>
        <Type>R</Type>
        <Direction>R</Direction>
        <Units>gradi</Units>
        <OfsValue>555</OfsValue>
        <ScaleFact>555</ScaleFact>
        <BitIgnore>02</BitIgnore>
        <SamplRate>03</SamplRate>
        <Delay>03</Delay>
        <MaxLatency>02</MaxLatency>
      </Register>
      <Register>
        <Address>0100</Address>
        <Name>register2</Name>
        <Type>B</Type>
        <Direction>I</Direction>
        <Units>t</Units>
        <OfsValue>5555</OfsValue>
        <ScaleFact>5555</ScaleFact>
        <BitIgnore>02</BitIgnore>
        <SamplRate>04</SamplRate>
        <Delay>44</Delay>
        <MaxLatency>04</MaxLatency>
      </Register>
    </Device>
    <Device>
      <Address>02</Address>
      <Name>dev2</Name>
      <Function>device 2</Function>
      <Register>
        <Address>0200</Address>
        <Name>register5</Name>
        <Type>B</Type>
        <Direction>B</Direction>
        <Mask>5555</Mask>
        <OfsValue>0</OfsValue>
        <ScaleFact>0</ScaleFact>
        <BitIgnore>00</BitIgnore>
        <SamplRate>03</SamplRate>
        <Delay>03</Delay>
        <MaxLatency>03</MaxLatency>
      </Register>
    </Device>
  </Node>
</ModbusConfigurator>

------WebKitFormBoundaryFfB4YR7FJLBRkPEY--

自动将这些行添加到我的 xml

 ------WebKitFormBoundaryFfB4YR7FJLBRkPEY
Content-Disposition: form-data; name="file"; filename="prova_Fld.xml"
Content-Type: text/xml

并在文件末尾

------WebKitFormBoundaryFfB4YR7FJLBRkPEY

我怎样才能删除它?我必须从 javascript 更改任何参数,或者我需要从 php 中删除我不需要的参数?

4

1 回答 1

0

此代码有效

<?php
header('Access-Control-Allow-Origin: *');
$number=0;
$final="";
$postText = file_get_contents('php://input'); 
for ($i = 0; $i <=strlen($postText); $i++) {
 if($postText[$i]=="<"){
    $number=$i;
    break;
}else{
 $postText[$i]="h";
}
   }
for ($i = strlen($postText)-1; $i >=0; $i--) {
if($postText[$i]==">"){
    $number2=$i;
    break;
}else{
 $postText[$i]="f";
}
}
for ($i = 0; $i <=strlen($postText)-$number; $i++) {
$postText[$i]=$postText[$i+$number];
 }
 for ($i = strlen($postText)-$number; $i<strlen($postText); $i++) {
   $postText[$i]="f";

}

$try=substr($postText, 0, strlen($postText)-$number-47);
于 2014-02-18T18:53:09.033 回答