0

我用一个函数实现了 SoapServer,它应该只转发接收到的带有发布请求的变量并从中获取响应。而不仅仅是返回响应。

无论我尝试什么(curl,file_get_contents,...),我都无法从该函数发出 post 请求 -> 没有任何东西从它发送,但没有错误

我确定我的 curl 代码有效,因为我单独对其进行了测试,并且通常发送了发布请求。所以我的问题是:是否甚至可以从 SoapServer 函数发送请求以及如何发送?

这是我到目前为止所拥有的: 服务器代码:

$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);
4

1 回答 1

0

感觉真的很愚蠢 :) 出于某种原因,我的 conf.php 文件在调用 Web 服务函数时没有被包含在内。问题解决了。

于 2013-02-11T08:56:32.000 回答