我使用一个函数实现了SoapServer,该函数应该只使用post请求转发收到的变量并从中获取响应。而不仅仅是回复。
无论我尝试什么(curl,file_get_contents,...),我都无法从该函数发出请求 - >没有任何东西从它发送,但没有错误
我确定我的卷曲代码有效,因为我单独测试它并且通常发送了发布请求。 所以我的问题是:甚至可以从SoapServer函数发出post请求以及如何?
这是我到目前为止所拥有的: 服务器代码:
$server = new SoapServer("../wsdl/DohvatiSlobodniTermin.wsdl");
//SERVICE FUNCTIONS:
function GetSlobodniTermini(GetSlobodniTermini $GetSlobodniTermini){
$mirth_listener=$conf->mirth_url."dohvatislobodnitermin/";
$data = $GetSlobodniTermini->poruka;
// use key 'http' even if you send the request to https://...
//$options = array('http' => array('method' => 'POST','content' => $data,'header'=> 'Content-Type: text/html\r\n'));
//$context = stream_context_create($options);
//$result = file_get_contents($mirth_listener, false, $context);
//return $result;
//set the url, number of POST vars, POST data
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $mirth_listener);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return new GetSlobodniTerminiResponse($result);
}
ini_set("soap.wsdl_cache_enabled","0");
$server->AddFunction("GetSlobodniTermini");
$server->handle();
和我的测试客户端代码:
$wsdl_link='http://localhost/test/service/dohvatislobodnitermin.php?wsdl';
$classmap_array=array(
'GetSlobodniTerminiResponse' => 'GetSlobodniTerminiResponse',
'GetSlobodniTermini' => 'GetSlobodniTermini'
);
$client = new SoapClient($wsdl_link, array('classmap' => $classmap_array));
$response = $client->GetSlobodniTermini(new GetSlobodniTermini(1, '333'));
print_r($response);
答案 0 :(得分:0)
感觉真傻:) 由于某种原因,仅调用Web服务功能时,我的conf.php文件没有被包括在内。问题解决了。