Reputation: 1664
I am attempting to consume a .NET webservice that is requesting a RequestObject of options and I have no idea how that works in cURL. Does anyone know?
For this webservice: https://uat.petfirsthealthcare.com/pfh.service.webservices/coreservice.svc/json/GetBreedList I need to send a Request Object 'CoreServiceGetBreedListRequest' with a value SpeciesId of 1.
Here is what I have, but missing the value.
$request = 'https://uat.petfirsthealthcare.com/pfh.service.webservices/coreservice.svc/json/GetBreedList';
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $request);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_SSLVERSION,3);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($session, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$response = curl_exec($session);
curl_close($session);
Thanks for any help!
Upvotes: 0
Views: 719
Reputation: 682
That is a SOAP service, not a REST service. Although you can probably consume it anyways using curl() by reading the WSDL definition and by trial and error, it is much easier to consume it using the SOAP libraries of PHP.
Use the SoapClient class. When it asks for a WSDL file, just pass:
https://uat.petfirsthealthcare.com/pfh.service.webservices/CoreService.svc?wsdl
Or download it, upload it to your server and set the path (but if the service changes, you may find issues). That file will give the SoapClient class the available methods and required parameters (and parameter types) to make the correct requests to the service. Watch out parameter types, as PHP tends to cast anything to string, and the SoapClient class is picky about parameter types (if the WSDL states it must be an integer, it may fail if you send a string, even if it is "3").
Upvotes: 2
Reputation: 3046
If you want to use cURL, you have to use CURLOPT_HTTPHEADER and pass an array of content type application/json as well as the content length.
In CURLOPT_POSTFIELDS you also send a properly formatted request like this:
$object = json_encode(array('Speciesid' => 1));
the content length is = strlen($object)
Upvotes: 1