Please note that after much research I decided to write here since I couldn't pin-point the problem. Although it exists widely on the net. Sorry for that.
I'm trying to get a response using SOAP (see code below):
<?php
$param = array(
'USERID'=>'some_user',
'PASSWORD'=>'some_pwd',
'MARKETTYPE'=>'333',
'INSTRUMENTTYPE'=>'C'
);
$url = 'https://www.x/x/x/x.serviceagent?wsdl';
try
{
$soap_client = new SoapClient($url);
$soap_client->providedFunction($param);
} catch (SoapFault $e) {
echo $e->getMessage();
}
?>
Note that this code is on my local wamp server. (I also tried it online on a beta site)
When I refresh the php file, I get the following 'Could not connect to host'.
I appreciate any help given.
Thanks
Related
I'm trying to connect to our moodle server via SOAP web service from PHP.
I'm trying to run the mod_assign_get_assignments function, but I'm receiving a 'invalidparameter' message.
I can get the function to return the expected data via REST, but need to get it working via SOAP.
Here is the code I'm using...
<?php
$serverurl = "http://moodlehost/webservice/soap/server.php?wsdl=1&wstoken=763b54a6exxxx989be353xxxx6cca5f6";
$soapClient = new SoapClient($serverurl);
try
{
$soapClient->__soapCall('mod_assign_get_assignments', array("courseids" => array(10889), "includenotenrolledcourses" => 1));
}
catch (Exception $e)
{
echo("<pre>");
print_r($e);
echo("</pre>");
}
?>
Can someone please try this against their own moodle server and see if you get an error as I am??
..or I'd love it if someone could point out what I'm doing wrong.
..is it just me, or is the moodle web services documentation hard to follow?
Can you check that you have SOAP turned on in your Web Service protocols admin. You can access this page at admin/settings.php?section=webserviceprotocols
Try clicking the eye with the strike through it to enable it (if it isn't already).
I am using SOAP in a php script to call a web service from a Linux Centos 6 server. In this week I have been getting could not connect to host error from soapCall method. Of course this exception does not happen all the time but I see this exception most of the time, for example if I call soapCall 5 times, this error happens 3 times. My code is as below and I have not changed it at all for some months but recently it gets this error most of the time.
$wsdl="http://x.x.x.x:x/gw/services/Service?wsdl";
//Set key as HTTP Header
$aHTTP['http']['header'] = "key:" .$key ."\r\n";
$context = stream_context_create($aHTTP);
try
{
$client = new SoapClient($wsdl,array("soap_version" => SOAP_1_2,'trace' => 1,"stream_context" => $context));
}
catch(Exception $e)
{
return "something";
}
//I make $parametrs
try
{
$res = $client->__soapCall("send",array($parametrs));
}
catch(Exception $e)
{
print_r($e->getMessage()); //Most of the time it prints could not connect to host
}
I have read most answers to related questions here but my problem has not been solved. Also I added
ini_set("soap.wsdl_cache_enabled", "0");
ini_set("soap.wsdl_cache_ttl","0");
but nothing changed. I searched a lot about the reason and I found something about SSL but I have not found exact solution.
It must be mentioned that I can see the wsdl URL in browser and I have it's ping.
I have the following PHP code, which up to a week or so ago was working to send Twitter direct messages to a particular user. I now get "HTTP_OAuth_Exception: Unable to connect to tcp://api.twitter.com:80. Error #0: php_network_getaddresses: getaddrinfo failed: Name of service not known in /usr/share/pear/HTTP/OAuth/Consumer.php on line 257"
I've searched around and can't find that anything has changed with Twitter since it was working and the server configuration also hasn't changed. I tried using SSL in case Twitter suddenly required connection via SSL, but that gave basically the same error (except it said ssl and port 443).
I'm at a loss to see what's wrong and don't believe anything changed on my side. My code is based on the example in the Services_Twitter documentation (http://pear.php.net/package/Services_Twitter/docs/latest/Services_Twitter/Services_Twitter.html#var$oauth)
Any help would be greatly appreciated.
require_once 'Services/Twitter.php';
require_once 'HTTP/OAuth/Consumer.php';
$twitterto = 'xxxxxxxxxxxx';
$message='This is a test message';
$cons_key='xxxxxxxxxxxx';
$cons_sec='xxxxxxxxxxxx';
$auth_tok='xxxxxxxxxxxx';
$tok_sec='xxxxxxxxxxxx';
try {
$twitter = new Services_Twitter();
$oauth = new HTTP_OAuth_Consumer($cons_key,
$cons_sec,
$auth_tok,
$tok_sec);
$twitter->setOAuth($oauth);
// The error is raised on the following line.
$twitter->direct_messages->new($twitterto, $message);
$twitter->account->end_session();
} catch (Services_Twitter_Exception $e) {
echo $e->getMessage();
}
I have one http: path and one wsdl file.
but it is not work in local ip and server ip.
it is work only mobile.
i want to check this webservice is working is not working.
If working, i want to get function list from wsdl.
How it?
Plz help me as soon as possible.
This will list the available functions from the service:
$client = new SoapClient('http://hostsite');
var_dump($client->__getFunctions());
You can use the BubbleSOAP php script:
try{
$client = new BubbleSOAP($wsdl_url);
$list=$client->__getFunctionsNames();
foreach($list as $name){
echo $name;
}
}
catch(Exception $e){
echo $e->getMessage();
}
https://github.com/andreaval/Bubble-SOAP
I make use of a great class made by Jaisen: http://github.com/jmathai/twitter-async/tree/master. Recently twitter has been up and down and I am sure it will continue to be the same in the future so I am trying to cut down on my dependency on twitter being actually working.
The following is what I have in my header.php and it is right at the top and it generates the login URL for each user. If twitter is down, my site hangs for as long as it needs to and it throws an exception. So I have to catch these expceptions which I have sort of done.
I now want to just cancel the request to the API after a few seconds and just load the page and keep trying behind the scenes. How can I best do this?
<?php include './twitter/EpiCurl.php'; include './twitter/EpiOAuth.php'; include './twitter/EpiTwitter.php';
$consumer_key = 'mykey';
$consumer_secret = 'mysecret';
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
try{
$twiturl = $twitterObj->getAuthenticateUrl();
$url = "window.open('".$twiturl."','Login', 'left=20,top=20,width=500,height=500,toolbar=0,resizable=1'); startLoad();";
}catch(EpiOAuthBadRequestException $e){
// bad request exception do something
$statusMessage = 'Oops an error has occurred: ' . $e->getMessage();
}catch(EpiOAuthUnauthorizedException $e){
// bad authorization..probably bad tokens, do something different
$statusMessage = 'Oops an error has occurred: ' . $e->getMessage();
}catch(EpiOAuthException $e){
// uh oh, unknown oauth exception
$statusMessage = 'Oops, an unknown authorisation error has occurred! The mojo team have been notified! Please try again.';
}
if(isset($statusMessage)){
}
?>
Any improvement of the above code will also be appreciated.
Thanks all
The library supports a value to be passed into the curl timeout.
$twitterObj->setTimeout($secs_request_timeout);
I just added support for passing in a connection timeout as well. Unable to run unit tests because I'm being rate limited. Will commit this once I can verify that it works.
$twitterObj->setTimeout($secs_request_timeout, $secs_connection_timeout);
Use curl_setopt(CURLOPT_CONNECTTIMEOUT, 1 /* 1 second timeout */); to cause CURL to give up if a connection isn't established in 1 second. I use this when connecting to the facebook API, 'cause they've been pretty unreliable in the past as well.