我正在使用API,并且是PHP SOAP的新手。我试图创建一个获取车辆值的请求,并希望获取响应值。
以下是SOAP 1.1请求示例。显示的占位符需要替换为实际值。
POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"
<?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>
<getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
<vehicleRequest>
<Vin>string</Vin>
<Region>int</Region>
<Mileage>int</Mileage>
</vehicleRequest>
</getDefaultVehicleAndValueByVin>
这是SOAP客户端URL调用-
$clientV = new soapclient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array(
// Stuff for development. 'trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
这是香港专业教育学院的尝试,但没有得到结果-
$clientV = new soapclient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array(// Stuff for development. 'trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
$params = new \SoapVar("<vehicleRequest><Vin>5YFBURHE3FP331896</Vin><Region>10</Region><Mileage>100000</Mileage></vehicleRequest>", XSD_ANYXML);
$result = $client->Echo($params);
我尝试过的另一种方法,但解析WSDL时出错
$wsdl = '
POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"
<?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>
<getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
<vehicleRequest>
<Vin>5YFBURHE3FP331896</Vin>
<Region>1</Region>
<Mileage>100</Mileage>
</vehicleRequest>
</getDefaultVehicleAndValueByVin>
</soap:Body>
</soap:Envelope>
';
try {
$clientC = @new SOAPClient($wsdl); for $wsdl
$response = $clientC->getDefaultVehicleAndValueByVin(array('key' => 'val'));
} catch (Exception $e) {
echo $e->getMessage();
}
die(var_dump($response));
这是我遇到的错误-
SOAP错误:解析WSDL:无法从POST /vehicles/vehicle.asmx HTTP / 1.1主机加载:webservice.nada.com内容类型:text / xml; charset = utf-8内容长度:长度SOAPAction:“ http://webservice.nada.com/vehicles/vehicle.asmx?wsdl” 5YFBURHE3FP331896 1100':无法加载外部实体“ POST /vehicles/vehicle.asmx HTTP / 1.1主机:webservice.nada.com内容类型:text / xml; charset = utf-8 Content-Length:长度SOAPAction:“ http://webservice.nada.com/vehicles/vehicle.asmx?wsdl”
答案 0 :(得分:1)
这样的事情应该可以帮助您入门。我不是100%熟悉NADA API,所以我不知道某些参数的有效值是什么...您必须填写正确的值(例如Token,Period,VehicleType和Region)
$clientV = new SoapClient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array('trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
$params = new stdClass();
$params->Token = '';
$params->Period = 1;
$params->VehicleType = '';
$params->Vin = '5YFBURHE3FP331896';
$params->Region = 1;
$params->Mileage = 100;
$result = $clientV->getDefaultVehicleAndValueByVin(array('vehicleRequest' => $params));