douhui1630 2014-04-27 14:33
浏览 65
已采纳

PHP肥皂响应返回NaN

i'm sorry if the title might misleading, i'm kinda dumb but could you give me a little hint for me.

i'm trying for bmi web service

soap request

 POST /webservices/bmiservice.asmx HTTP/1.1
    Host: www.beetledev.com
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://www.beetledev.com/getBmiValue"

   <?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>
        <getBmiValue xmlns="http://www.beetledev.com">
          <w>double</w>
          <h>double</h>
        </getBmiValue>
      </soap:Body>
    </soap:Envelope>

soap response

HTTP/1.1 200 OK
   Content-Type: text/xml; charset=utf-8
   Content-Length: length

   <?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>
       <getBmiValueResponse xmlns="http://www.beetledev.com">
         <getBmiValueResult>double</getBmiValueResult>
       </getBmiValueResponse>
     </soap:Body>
    </soap:Envelope>

PHP coding

<?php
require_once "lib/nusoap.php";
$client = new nusoap_client("http://www.beetledev.com/webservices/bmiservice.asmx");

$error = $client->getError();
if ($error) {
    echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}

$result = $client->call('getBmiValue',array('w' => 62, 'h' =>167),null, 'http://www.beetledev.com/getBmiValue');


if ($client->fault) {
    echo "<h2>Fault</h2><pre>";
    print_r($result);
    echo "</pre>";
}
else {
    $error = $client->getError();
    if ($error) {
        echo "<h2>Error</h2><pre>" . $error . "</pre>";
    }
    else {
        echo "<h2>BMI</h2><pre>";
        echo $result;
        echo "</pre>";
    }
}

echo "<h2>Request</h2>";
echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
echo "<h2>Response</h2>";
echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";
?>

result

BMI

NaN

Request

POST /webservices/bmiservice.asmx HTTP/1.0
Host: www.beetledev.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.beetledev.com/getBmiValue"
Content-Length: 476

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><getBmiValue><w xsi:type="xsd:int">62</w><h xsi:type="xsd:int">167</h></getBmiValue></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response

HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Sun, 27 Apr 2014 14:26:40 GMT
Connection: close
Content-Length: 364

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getBmiValueResponse xmlns="http://www.beetledev.com"><getBmiValueResult>NaN</getBmiValueResult></getBmiValueResponse></soap:Body></soap:Envelope>

i dont know where i do wrong, i'm hoping for a little hint

Thank you

  • 写回答

1条回答 默认 最新

  • dongzhong2674 2014-04-28 15:39
    关注

    i found the solution to my problem

    first

    $client = new nusoap_client("http://www.beetledev.com/webservices/bmiservice.asmx");
    

    change to

    $client = new nusoap_client('http://www.beetledev.com/webservices/bmiservice.asmx?WSDL',TRUE);
    

    second

    $result = $client->call('getBmiValue',array('w' => 62, 'h' =>167),null, 'http://www.beetledev.com/getBmiValue');
    

    change to

    $result = $client->call('getBmiValue',array('w' => 62,'h'   => 167));
    

    third

    the thing is because there are two variable? (not sure with term), so it was kept in an array

    please dont mind the variable name

    $fConversionRate = (float) $result['getBmiValueResult'];
    

    and done and i get my bmi result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。