[英]Any way to force PHP SOAP to call HTTPS instead of HTTP?
I have a VERY simple PHP code:我有一个非常简单的 PHP 代码:
<?php
$soap = new SoapClient('https://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl', array());
var_dump($soap);
When I copy that URL into my browser it loads just fine, with no redirects or anything: $soap = new SoapClient('https://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl当我将 URL 复制到我的浏览器中时,它加载得很好,没有重定向或任何东西: wsdl
But when I execute that PHP script I get the following error after a PHP timeout:但是,当我执行 PHP 脚本时,在 PHP 超时后出现以下错误:
Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0' : failed to load external entity "http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0"
Notice the response URL is http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0
which is very similar but not quite accurate.注意响应 URL 是
http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0
If I search the working WSDL for that given URL I find it at the top:如果我为给定的 URL 搜索有效的 WSDL,我会在顶部找到它:
That said, every URI points to HTTP instead of HTTPS, but if we simply change this in our browser the page loads just fine.也就是说,每个 URI 都指向 HTTP 而不是 HTTPS,但是如果我们在浏览器中简单地更改它,页面加载就很好了。
So the question becomes: when we create a PHP SoapClient, can we force all URIs to follow HTTPS regardless of the protocol specified in the WSDL?那么问题就变成了:当我们创建一个 PHP SoapClient 时,我们是否可以强制所有 URI 遵循 HTTPS 而不管 WSDL 中指定的协议如何?
The WSDL can stand by itself and contain everything inside, or it can use imports to bring in content from other locations (it usually happens with XSD schemas). WSDL 可以独立存在并包含内部所有内容,也可以使用导入从其他位置引入内容(通常发生在 XSD 模式中)。
If it imports things, those imports need to be resolved by the client.如果它导入东西,则这些导入需要由客户端解决。 If they can't be resolved, either because the location is wrong, or the protocol is wrong, or whatever, then the client bails out, because it needs a complete WSDL to understand the service's contract and how to call it, not just the parts it could load.
如果由于位置错误或协议错误或其他原因无法解决它们,则客户端会退出,因为它需要完整的 WSDL 来了解服务的合同以及如何调用它,而不仅仅是它可以加载的部分。
So you have two options:所以你有两个选择:
VehicleService.wsdl
for the WSDL itself, and VehicleService.xml
for the file you got from http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0
somehow, you can then change the WSDL to import this local file with <wsdl:import.... location="VehicleService.xml" />
instead of what it does right now. VehicleService.wsdl
for the WSDL itself, and VehicleService.xml
for the file you got from http://rev-int.api.us.fleetmatics.com/Vehicle/SageQuest/VehicleService.svc?wsdl=wsdl0
以某种方式,然后您可以更改 WSDL 以使用<wsdl:import.... location="VehicleService.xml" />
导入此本地文件,而不是现在执行的操作。 Then you can feed this local WSDL to your client, and because now everything is in the same folder, it should work.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.