使用NuSOAP Web服务客户端时出错

时间:2017-07-18 09:11:05

标签: php html5 soap nusoap

我在PHP中使用NuSOAP时面临“HTTP错误:不支持的HTTP响应状态404未找到(soapclient->响应具有响应内容)”的问题。这是服务器的代码:

<?php
require_once "nusoap.php";

function getProd($category) {
    if ($category == "books") {
        return join(",", array(
            "The WordPress Anthology",
            "PHP Master: Write Cutting Edge Code",
            "Build Your Own Website the Right Way"));
    }
    else {
        return "No products listed under that category";
    }
}

$server = new soap_server();
$server->register("getProd");

$server->service($HTTP_RAW_POST_DATA);

以下是客户端请求的代码:

<?php
require_once "nusoap.php";
$client = new nusoap_client("http://localhost/nusoap/productlist.php");

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

$result = $client->call("getProd", array("category" => "books"));

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>Books</h2><pre>";
        echo $result;
        echo "</pre>";
    }
}

2 个答案:

答案 0 :(得分:1)

我的网址错误了 $ client = new nusoap_client(&#34; http://localhost/nusoap/productlist.php&#34;); 我将其更改为:$ client = new nusoap_client(&#34; http://localhost/testcases/nusoap/productlist.php&#34;);  现在工作正常。

答案 1 :(得分:0)

由于响应状态404 导致的错误通常是由错误的网址路径引起的。