将温度从摄氏温度转换为华氏温度

时间:2015-05-27 20:59:30

标签: php soap

我正在开发一个简单的Web服务,应该将温度从摄氏温度转换为华氏温度

但我得到一个空字符串作为输出:

string(0) "" 

这是我的代码:

<?php 
$soapUrl = "http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit";

$xml_post_string = '
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
      <Celsius>58</Celsius>
    </CelsiusToFahrenheit>
  </soap:Body>
</soap:Envelope>';  

$headers = array(
                "Content-Type: text/xml; charset=utf-8",
                "Content-Length: ".strlen($xml_post_string),
                "SOAPAction: http://www.w3schools.com/webservices/CelsiusToFahrenheit",
            ); 

$url = $soapUrl;

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

// converting
$response = curl_exec($ch); 
curl_close($ch);
var_dump($response);exit;

如我的代码所示,我在帖子字符串中传递 58 并期望它转换为华氏温度,但它没有发生。

我已经在剧本上工作了好几个小时,似乎无法找出问题

希望被指向正确的方向

0 个答案:

没有答案