我正在尝试验证网站。我找到了一个PHP的例子,但我在将它重写为Ruby时遇到了一些麻烦。
示例代码:
class HRDConfig {
public $uid = "myuid";
public $pass = "mypassword123";
const NS = "https://www.tested.site.com/partnerAPI/";
const PARTNER = "https://www.tested.site.com/partnerAPI/Partner.php?wsdl";
}
ini_set("soap.wsdl_cache_enabled", "1");
$soap = new SoapClient(HRDConfig::PARTNER, array("encoding"=>"UTF-8", "exceptions" => true));
$soap->__setSoapHeaders(array(new SoapHeader(HRDConfig::NS, "AuthHeader", new HRDConfig())));
我的代码:
client = Savon.client(
wsdl: 'https://www.tested.site.com/partnerAPI/Partner.php?wsdl',
soap_header:{
'AuthHeader' => {'uid'=>'myuid','pass'=>'mypass'}
})
我做错了什么?
答案 0 :(得分:0)
$client = new SoapClient(
'http://service.example.com?wsdl',
array('soap_version' => '1.2',
'connect_timeout' => 10,
'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP),
'cache_wdsl' => WSDL_CACHE_NONE));
$header = new SoapHeader(
'http://service.example.com?wsdl',
'AuthenticateRequest',
new SoapVar(array('apiKey' => '***api******'), SOAP_ENC_OBJECT),
true);
$client->__setSoapHeaders($header);
try {
echo("\n[SOAP response]\n");
$response = $client->__soapCall('your function', array());
echo("\n[After response]\n");
echo("\n{$response }\n");
}
catch (Exception $e) {
echo($e->getMessage());
}
注意:这里" apiKey"是我的证明api的参数,你可以是不同的