使用 NuSOAP 网络服务客户端时出错

Error using NuSOAP webservice client

我在 php 中使用 NuSOAP 时遇到 'HTTP Error: Unsupported HTTP response status 404 Not Found (soapclient->response has contents of the response)' 的问题。这是服务器的代码:

<?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>";
    }
}

我错了url $client = new nusoap_client("http://localhost/nusoap/productlist.php"); 我将其更改为:$client = new nusoap_client("http://localhost/testcases/nusoap/productlist.php"); 现在一切正常。

由于响应状态404导致的错误通常是由不正确的url路径引起的。