【问题标题】:PHP SoapClient - Creating a request with a variablePHP SoapClient - 使用变量创建请求
【发布时间】:2019-02-16 09:23:28
【问题描述】:

我正在尝试在 PHP 中创建一个 SOAP 请求。我对此很陌生,而且很挣扎。我正在使用的 Web 服务将车辆的 VIN 作为输入,然后发回有关该特定车辆的详细信息。输入:1ZVHT88S375260112 作为回报,您将收到有关该 VIN 所属的 2007 Ford Mustang 的详细信息。

我创建了一个简单的输入栏和表单来输入 VIN。这将使用 PHP SOAP 请求输入页面。我还用我的 WSDL 链接创建了一个 SOAP 信封。我省略了我的登录凭据(用户名和密码/密码)。

如何获取 VIN 输入和我的信封并在 PHP 中使用 SoapClient 创建一个 SOAP 请求?任何输入或帮助将不胜感激!

简单的 HTML 输入/表单:

<!DOCTYPE html>
<html>

<head>
<title>VIN Decoder API Test</title>

<style type="text/css">
input {width: 700px;height:50px;display: block;margin-left: auto;margin-right: auto;margin-top: 200px;font-size:36px;font-family: sans-serif;text-align: center;}
button {display: block;margin-left: auto;margin-right: auto;}
.display1 {display: flex;align-items: center;justify-content: center;}
.button1 {
    background-color: rgba(30, 31, 35);
    border: none;
    color: rgba(215, 214, 219);
    padding: 10px 50px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 28px;
    cursor: pointer;
    font-family: sans-serif;
}
</style>

</head>

<body>

    <form action="request.php" method="post">

    <input type="text" id="VIN" placeholder="Enter VIN" name="VIN" maxlength="100"/>
    <br>
    <div class="display1">
    <button id="submit_btn" class="button1">Submit</button>
    </div>

  </form>

  <br>
  <br>

</body>
</html>

肥皂信封:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:description7b.services.chrome.com">
<soapenv:Header/>
 <soapenv:Body>
  <urn:VehicleDescriptionRequest>
     <urn:accountInfo number="" secret="" country="US" language="en" behalfOf="?"/>
     <urn:vin>$VIN</urn:vin>
  </urn:VehicleDescriptionRequest>
 </soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

标签: php soap soap-client


【解决方案1】:

如果您的肥皂信封位于一个名为信封.txt 的文件中,您可以在您的 php 页面中执行此操作:

$soapenv = file_get_contents('/path/to/envelope.txt');
$prepared_envelope = str_replace("$VIN", $VIN, $soapenv);

这会将您的信封加载到一个变量中,然后将 var 替换为 var 的值。有几种方法可以做到这一点,但这是最容易解释的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    相关资源
    最近更新 更多