Magento Soap client is not working on https - php

I have facing issue on Magento soap api connection whenever try to use https as secure url.
My magento system version CE 1.7 and soap version 1.
System Url setup is
Secure url is https://www.example.com/
Unsecured is http://www.example.com/
When i am changed secure to http://www.example.com/(With out https)
Then the soap client is working properly.
Also,when secure is https://www.example.com ,it throw below error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://www.example.com/index.php/api/soap/index/?wsdl' : failed to load external entity "https://www.example.com/index.php/api/soap/index/?wsdl
My code is
try{
$cli = new SoapClient('http://www.example.com/index.php/api/soap/index/?wsdl');
$session = $cli->login('marketplace_usr', 'ezvendorplus');
$result = $cli->call($session, 'catalog_product.info', 10887);
var_dump($result);
}
catch(Exception $e){
echo '<pre>';
var_dump($e);
}

Check is php_openssl extension enabled. If not - enable it.

It is server site issue.Hosting provider is resolved the issue by
add a ssl vhost on private ip for www.example.com and reload apache
and also made a host file entry

Related

Getting SOAP error when parsing WSDL from an API when the website hosting has been changed

Switched hosting and I have been encountering a SOAP error. The PHP version I am running is 7.3 and the previous hosting was 7.2. The URL that the soap client is trying to access is open and allows anyone to access it. SOAP has been enabled on cPanel.
<?php
try{
$soapclient = new SoapClient('http://url/Schedule_service.asmx?re_Status&WSDL');
$param = array('TheatreId'=>101,'FilmId'=>0);
$response = $soapclient->FnSchedule_Film_Theatre_Status($param);
$coming_result = json_decode(json_encode($response),true);
}catch(Exception $e){
echo $e->getMessage();
}
?>
The error message is displayed on the website is, where URL is the soap client url:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://url' failed to load external entity 'http://url'

Symfony SSL connect error for in http client

I use http client component in my project symfony for external apis but I found this error when i test api:
SSL connect error for url
configuration of component is basic configuration and also create for request if simple with request method
$client = $this->client->request(
'GET',
$this->getUrl($route) . $query,
$this->options
);
I use a certificate for https and I enabled openssl extension, also I try to user verify_peer option in options parameters but also error.
How to fix this error?

Soap client stopped working

I have a website which frequently makes SOAP calls to a particular API. The site was working fine for a few months of time, however the SOAP functionality suddenly stopped working without any known reason, the error was "Cannot connect to host".
The WSDL service has not moved or shut down.
After this I updated plesk from version 12 to version 17. SOAP client is still not working but now its a different error:
SOAP-ERROR: Parsing WSDL: Couldn't load from (URL) : failed to load external entity (URL)
This is my SOAP call:
$opts = array('http'=>array('user_agent' => 'PHPSoapClient'));
$context = stream_context_create($opts);
libxml_disable_entity_loader(false);
$client = new SoapClient($url,array('stream_context' => $context,'cache_wsdl' => WSDL_CACHE_NONE));
Any possible solutions?
EDIT:
New information came in, so the API server had DNS problems, how can I restore my connection to the API?
Your php server is clearly not reaching out the soap server. This might help:
Try checking directly from php server if the service are reachable:
wget {url} > page.txt
nano (or equivalent) page.txt
Try using other program to consume the server, I suggest Soap Ui
On the php server try ping the service url and see if the IP is resolved.
Check if any other soap service is reachable, you can use this service
If this not help you coming up with a solution, post here the results to help others solving it.

php soap client returns 404, when calling WSDL methods from HTTPS environment

I am running a php soap client example under https environment of my Zend Server.
I am able to list the methods in the WSDL. But when i make a call to one of those methods, i receive a 404 HTTP not found error. I also tried saving the WSDL to my local folder.
Interestingly, the same example was running successfully from the CLI (like: C:/> php abc.php). Not sure why it is failing in the browser (like: https://example.com:10022/abc.php).
This is my code:
<?php
ini_set("soap.wsdl_cache_enabled", "0");
try {
$client = new SoapClient('country.wsdl');
//$client = new SoapClient('http://www.webservicex.net/country.asmx?WSDL');
//$functions = $client->__getFunctions (); var_dump ($functions); // works
$params = array('CountryName'=> 'Australia');
$result = $client->GetISOCountryCodeByCountyName($params);
echo $result->GetISOCountryCodeByCountyNameResult;
}
catch(SoapFault $fault) {
echo $fault->getMessage();
}
?>
Note:
I have openssl enabled.
My https url is configured as a Zend server Virtual Host, running on port 10022.
My https url is not reachable from outside world (does this make any difference?)

file_get_contents - failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

I'm having some weird problems with file_get_contents after moving my site to a new domain. I had to set up a new domain and IP address (using Plesk) to get a new ssl certificate working. Now my file_get_contents calling a script on the same domain is giving me this:
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
If I call the same url using file_get_contents on another server it works fine, and if I call www.google.com from the server thats failing that works, so it only seems to be if I call a url on the same sever!
I have a feeling it might have something to do with having two IPs with two different ssl certificates on the one server, when i file_get_contents / (index page) of the server from the server I get the plesk 'this is a new domain' page so its like apache isnt looking up the right virtual host when its called from its own sever.
To clarify (hopefully!):
On the server hosting the domain:
file_get_contents('https://mydomain.com?limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12');
gives "failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found"
file_get_contents('http://www.google.com');
works correctly
On another server:
file_get_contents('https://mydomain.com?limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12');
works fine.
I have tried turning ssl off and I still get the same problem.
I've had this problem too, when I working on a little test server at home. The domain name is resolved to your external IP address, and a request is sent. But because the request is coming from inside your network, the router doesn't recognise it as a normal request. It probably has a web interface for configuring it, and tries to return a page from its own management system, which is then not found at the path you specified.
In that case, I was working on a Windows PC, and I could solve it by adding the domain I was testing to my hosts file, specifying 127.0.0.1 as the IP-address (or the IP-address of the server, if it is another machine within the same network). In Linux there should be a similar solution, I think.
The problem isn't PHP or your server, but your router.
If you just need to handle the warning when the URL is not found (as I did), you may just do this to turn Warnings into Exceptions:
set_error_handler(
function ($err_severity, $err_msg, $err_file, $err_line, array $err_context) {
// do not throw an exception if the #-operator is used (suppress)
if (error_reporting() === 0) return false;
throw new ErrorException( $err_msg, 0, $err_severity, $err_file, $err_line );
},
E_WARNING
);
try {
$contents = file_get_contents($your_url);
} catch (Exception $e) {
echo $e->getMessage();
}
restore_error_handler();
Solution based on this thread/question.
Most hosting provides now block the furl_open parameter which allows you to use file_get_contents() to load data from an external url.
You can use CURL or a PHP client library like Guzzle
Try to do this :
file_get_contents('https://mydomain.com?'.urlencode('limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12'));
I got the same error in CodeIgniter 3. I was doing like this
file_get_contents(base_url('database.json'));
and then this
file_get_contents(site_url('database.json'));
My problem get resolved after I changed it to this
file_get_contents(__DIR__.'/database.php');
Reason behind this was, I was trying to get the internal resource from external url which these methods base_url and site_url return. While __DIR__ return internal url.

Categories