The following soap request
$response = $this->client->__soapCall('Match', array('word' => 'test', 'strategy' => 'exact'));
yields the error
Uncaught SoapFault exception: [soap:Client] Parameter not specified (null)
Parameter name: word
How can this be? I specified the word parameter in the request, didnt I? Why doesn's the server recognize it?
The service I want to use is an online dictionary webservive
Generally you need to wrap the arguments in a double array:
$response = $this->client->__soapCall('Match', array(array('word' => 'test', 'strategy' => 'exact')));
It reads a bit nicer if you
$aParams = array('word' => 'test', 'strategy' => 'exact');
$response = $this->client->__soapCall('Match', array($aParams));
Or you can simply call the Match function directly
$aParams = array('word' => 'test', 'strategy' => 'exact');
$response = $this->client->Match($aParams);
Or, as a final resort, use the HTTP GET option: http://services.aonaware.com/DictService/DictService.asmx?op=Match
Should get you on the road again.
Related
I'm trying to make a json call with a variable, but keep getting an error since the call isn't registering quotes.
The following syntax makes the notification push send correctly:
'include_player_ids' => array('00000000-6fee-11e4-8ec9-000000000000')
Where as this method causes it to fail:
$playerID = '00000000-6fee-11e4-8ec9-000000000000';
...
'include_player_ids' => array($playerID)
The reason being the api requires the quotes around the array item, but I'm not too great at php and can't figure out how to add them around it since this method isn't working for me:
'include_player_ids' => array(' . $playerID . '),
Good (working) output:
"include_player_ids":["00000000-6fee-11e4-8ec9-000000000000"]
Bad (non-working) output:
"include_player_ids":[00000000-6fee-11e4-8ec9-000000000000]
Sending the POST request as json (with header set to "Content-Type" => "application/json") should work:
$fields = (object) [
'app_id' => $this->appId,
'include_player_ids' => $playerIds,
'template_id' => '374e7074-f07d-4743-ad90-5598967e4494', // `daily generic`
];
json_encode($fields);
I've been struggling with this for a few days now - I need to send a set of data encoded in json to an api. I'm trying to use Zend 2 http to achieve this but I've had no luck so far. Here is what the manual for the api says :
Bulk Create Contacts
This command can be used to insert new numbers into your Textlocal contact groups
and will allow you to insert extra fields such as the contact's name.
Parameter Description
group_id ID of the group you’d like to store the numbers in. This
contacts A JSON object containing all the details for each contact.
Note: It is recommended to send this request via POST.
Sample Request
(POST Variables):
username: testing#Textlocal.co.uk
hash: 4c0d2b951ffabd6f9a10489dc40fc356ec1d26d5
group_id: 5
contacts: [{"number":"447123456789","first_name":"Bob","last_name":"Smith","custom1":"","custom2":"","custom3":""},{"number":"447987654321","first_name":"Sally","last_name":"McKenzie","custom1":"","custom2":"","custom3":""},{"number":"447000000000","first_name":"Ramesh","last_name":"Dewani","custom1":"","custom2":"","custom3":""}]
Ok so that's what it expects and this is my code so far :-
include 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
use Zend\Http\Client;
use Zend\Http\Request;
$data = array(
'username' => 'myUsername',
'hash' => 'myHash',
'group_id' => 123456,
'contacts' => json_encode(array('number'=>447123456789,'first_name'=>'Bob','last_name'=>'Smith','custom1'=>"",'custom2'=>"","custom3"=>""))
);
$uri = 'https://api.txtlocal.com/create_contacts_bulk';
$request = new Request();
$request->setUri($uri);
$request->setMethod('POST');
$request->getPost()->set($data);
$config = array(
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'ssltransport' => 'ssl',
'sslcert' => '/etc/pki/tls/cert.pem',
'sslcapath' => '/etc/pki/tls/certs'
);
$client = new Client(null, $config);
$client->setEncType(Client::ENC_FORMDATA);
$response = $client->dispatch($request);
if ($response->isSuccess()) {
echo "the post worked!";
}else{
echo "the post failed";
}
That's not working and I'm sure there's I'm missing - here are the errors I get when I fire that script : -
[Thu Oct 24 09:29:47 2013] [error] [client] PHP Warning: Missing argument 2 for Zend\\Stdlib\\Parameters::set(), called in zend_test.php on line 24 and defined in Zend/Stdlib/Parameters.php on line 110
[Thu Oct 24 09:29:47 2013] [error] [client] PHP Notice: Undefined variable: value in Zend/Stdlib/Parameters.php on line 112
[Thu Oct 24 09:29:47 2013] [error] [client] PHP Fatal error: Uncaught exception 'Zend\\Http\\Client\\Exception\\RuntimeException' with message 'Cannot handle content type '' automatically' in Zend/Http/Client.php:1218\nStack trace:\n#0 Zend/Http/Client.php(858): Zend\\Http\\Client->prepareBody()\n#1 Zend/Http/Client.php(798): Zend\\Http\\Client->send(Object(Zend\\Http\\Request))\n#2 zend_test.php(30): Zend\\Http\\Client->dispatch(Object(Zend\\Http\\Request))\n#3 {main}\n thrown in Zend/Http/Client.php on line 1218
Any light you can shed or help you can give me would be greatly appreciated :)
Thanks in advance
Joe
You need to set the enc type when adding post data to the request object (this isn't very clear in the docs). Also, the example from the API manual implies that it's only the contacts that need to be JSON, you've encoded the whole array.
Try this:
$data = array(
'username' => 'myUsername',
'hash' => 'myHash',
'group_id' => 123456,
'contacts' => json_encode(array('number'=>447123456789,'first_name'=>'Bob','last_name'=>'Smith','custom1'=>"",'custom2'=>"","custom3"=>""))
);
$request = new Request();
$request->setUri('https://api.txtlocal.com/create_contacts_bulk');
$request->setMethod('POST');
$request->getPost()->fromArray($data);
$client = new Client();
$client->setEncType(Client::ENC_FORMDATA);
$response = $client->dispatch($request);
if ($response->isSuccess()) {
echo "the post worked!";
}else{
echo "the post failed";
}
Edit: In order to verify that the SSL certificate is valid, the HTTP client needs the path to the CA certificates on your web server.
You pass this in as a config option to the Http client instance:
$client = new Client(null, array(
'sslcapath' => '/etc/ssl/certs'
));
That's the path on Ubuntu, you'll need to find out what it is for your server.
By the way, instead of long constructions of Request, Response and Client classes please conider static Client usage:
http://framework.zend.com/manual/2.0/en/modules/zend.http.client-static.html
use Zend\Http\ClientStatic;
// Simple GET request
$response = ClientStatic::get('http://example.org');
// More complex GET request, specifying query string 'foo=bar' and adding a
// custom header to request JSON data be returned (Accept: application/json)
$response = ClientStatic::get(
'http://example.org',
array( 'foo' => 'bar' ),
array( 'Accept' => 'application/json')
);
// We can also do a POST request using the same format. Here we POST
// login credentials (username/password) to a login page:
$response = ClientStatic::post('https://example.org/login.php', array(
'username' => 'foo',
'password' => 'bar',
));
I'm trying to call a function from this webservice:
http://www.zulutrade.com/WebServices/Performance.asmx?WSDL
I'm sending all the requested params but I'm getting this error: Value cannot be null. Parameter name: source
I think it's a server issue, but maybe I need to change something in my code:
$client = new SoapClient('http://www.zulutrade.com/WebServices/Performance.asmx?WSDL',
array('location' => "http://www.zulutrade.com/WebServices/Performance.asmx",
'trace'=>1,
"cache_wsdl" => 0));
$params = array
(
'providerId' => 109206,
'fromDateStr' => "1985-12-19",
'toDateStr' => "2013-05-06",
'validTrades' => true,
'lotSize' => "Mini",
'start' => 0,
'length' => 20,
'sortBy' => "buy",
'sortAscending' => true
);
try
{
$result = $client->GetProviderTrades($params);
}
catch (SoapFault $fault)
{
print_r($fault);
}
Any ideas?
thanks
I tried with nusoap class and I get this error
HTTP Error: Couldn't open socket connection to server http://www.zulutrade.com:81/WebServices/Performance.asmx, Error (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
So maybe it's a bug on their part
You set all vars except one. ArrayOfInt currencyIds; is not set.
struct GetProviderTrades {
int providerId;
ArrayOfInt currencyIds;
string fromDateStr;
string toDateStr;
boolean validTrades;
LotSize lotSize;
int start;
int length;
string sortBy;
boolean sortAscending;
}
when i call a method and var_dump($result) then show bool(false) why?
i change my parameters to example and 1234 for writing here:
require_once('../class/nusoap.class.php');
// Create the client instance
$client = new soapclient('sample?wsdl' ,'wsdl', '', '', '', '');
$soapClient->soap_defencoding = 'UTF-8';
$soapClient->debug_flag = false;
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
// At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call('enqueue', array('from' => '+12345',
'rcpt_array' => '123456',
'msg' => 'hi',
'uname' => 'example1',
'pass' => 'example2'));
var_dump($result);
As per PHP SoapClient documentation the second parameter for the SoapClient constructor should be an array
public SoapClient::SoapClient ( mixed $wsdl [, array $options ] )
But in your case you're passing series of arguments. I'm not sure this will work or not.
Secondly while working with Soap calls with wsdl we can directly call the wsdl method like this as per your example with the parameters.
$client->enqueue(array('from' => '+12345',
'rcpt_array' => '123456',
'msg' => 'hi',
'uname' => 'example1',
'pass' => 'example2'));
Here is a simple PHP soap call example
i am trying to calling .net webservice in php
below is my code.
<?php
$client = new SoapClient("http://test.etech.net/PanelIntegration/PanelIntegration.asmx?wsdl");
<?php
$sh_param = array(
'Username' => 'IntegratorLPI',
'Password' => 'password531');
$headers = new SoapHeader('http://wms.etech.net/', 'UserCredentials', $sh_param);
$client->__setSoapHeaders($headers);
$params = array('CustomerName' => 'Mr Smith','ContactMobileNo' => '01237 376347',
'AddressLine1' => '33 Amblecote Road',
'AddressTown' => 'Cambridgeshire',
'AddressPostCode' => 'NW23 6TR',
'VendorAddressLine1' => '80 Norton Road',
'VendorAddressTown' => 'Hickley ',
'VendorAddressCounty' => 'Cambridgeshire',
'VendorAddressPostCode' => 'NW23 2AQ',
'RegionalOfficeID' => '3',
'ExternalNotes' => 'Case Accepted',
'UPRN' => '',
'InstructionTypeID' => '2',
'PropertyTypeID' => '11',
'PropertyTenure' => '2',
'SurveyorID' => '23',
'RRN' => '0240-9002-0391-3520-0020',
'NewInstruction'=> 'true',
'StatusID' => '1'
);
$result = $client->__soapCall("UpdateInstruction", $params );
print_r( $result);
?>
i have got this error
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\xampp\htdocs\test2.php:33 Stack trace: #0 C:\xampp\htdocs\test2.php(33): SoapClient->__soapCall('UpdateInstructi...', Array) #1 {main} thrown in C:\xampp\htdocs\test2.php on line 33
You probably need to send something like:
$result = $client->__soapCall("UpdateInstruction", array('Instruction' => $params );
Where Instruction is the name of the object that you are passing.
It looks like a NullReferenceException was thrown on the server side. So, it's a matter of the parameters to whatever function is occurring on the server side generating that error.
Regardless of why, per best practices, this is an error in the .NET service. The NullReferenceException should really be replaced with something more specific.
Can you get in touch with whomever wrote the service to get more information to troubleshoot? It's quite possible that you have a parameter misnamed in your $params array, but you're probably going to need some help from the service writer.