0

I implemented SoapServer with one function which should just forward received variable with post request and get response from it. than just return response.

Whatever I try (curl, file_get_contents, ...) ,I just can't do post request from that function -> nothing is send from it but goes without errors

I'm sure my curl code works because I tested it separately and post request was normally sent. So my question is: Is it even possible to do post request from SoapServer function and how?

Here's what i have so far: Server code:

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

and my test client code:

$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);
Rodrigo Guedes
  • 1,169
  • 2
  • 13
  • 27
rat
  • 51
  • 6

1 Answers1

0

Feeling really stupid :) My conf.php file didn't get included when just calling web service function for some reason. Problem solved.

rat
  • 51
  • 6