Magento API access on localhost without using internet connection - php

I have installation of magento 1.6.1 on local machine i\’m trying to connect magetno\’s api in php using following code
$proxy = new SoapClient('http://localhost/magento/api/v2_soap/?wsdl');
$sessionId = $proxy->login('apiuser', 'apikey');
I can connect using this code if internet connection on, If I make it off it doesn't work.
it gives following errors
Warning: SoapClient::SoapClient() [soapclient.soapclient]: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\wamp\www\magentomanager\api\products.php on line 12
Warning: SoapClient::SoapClient(http://schemas.xmlsoap.org/soap/encoding/) [soapclient.soapclient]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\wamp\www\magentomanager\api\products.php on line 12
please let me know what is the reason behind that?.
why magento needed internet connection for accessing local api. how do I access api without having without internet connection?

Magento's API is based on SOAP, as you may have found out. SOAP is based on XML and uses therefor schema files, which desribes the schema/layout for the SOAP calls for this service. So this file might be loaded before/on every SOAP call.
However, a workaorund could be to store the schema description on your local machine and editing Magento's wsdl.xml files, so that they will reference to your local machine. Simply search for the URL in all xml files inside your Magento installation.
Not a very nice workaround, but hey,... it's a workaround.

I think the problem is that localhost can't be resolved to your local IP or 127.0.0.1. You can add it in your host file or call it thru http:/// instead of http://localhost

Related

PHP - SoapClient::SoapClient failed to open stream: Connection refused

I'm trying to integrate a PHP portal with a CRM(microsoft dynamics .NET) system using SOAP.
This is part of my code:
$client = new SoapClient("http://XX.XXX.X.XX:5050/host.svc?wsdl");
This line returns 2 errors
Warninig: Message: SoapClient::SoapClient(http://80.248.5.35:5050/host.svc?wsdl): failed to open stream: Connection refused
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://XX.XXX.X.XX:5050/host.svc?wsdl' : failed to load external entity
Opening the link in the browser works and running this code in my local machine(localhost) works also.
i've tried file_get_contents("http://XX.XXX.X.XX:5050/host.svc?wsdl"); but this returns a warning message
Message: file_get_contents(http://80.248.5.35:5050/host.svc?wsdl): failed to open stream: Connection refused
i've tried so many solutions from stackoverflow.
If anyone could help me with this or shed more light on the situation cause this is my first attempt at something like this. Thanks
I found out the problem.
My webserver was denying me from making outgoing connection through any port rather than the default port. i fixed it by changing the web service to the default port on the ISS
I've been frustrated by this "failed to open stream" error too, but from the point of view of trying to connect to a web service from the web.
However, the issue is the same underneath: your web server needs to be able to reach the web service from itself.
My solution if you are using a Windows Server: add an entry to your windows host file to allow loopback on the server for the external domain you're using for the web service.
So, open your "hosts" file, which is usually in somewhere like C:\Windows\System32\drivers\etc. Then add a line like:
<machine LAN IP like 192.168.1.1 or 127.0.0.1> <domain.ofwebsevice.com>

Ubuntu iptable messing file_get_contents() up

I am setting my ubuntu web server up and I am setting up a firewall on it. All is good except for my one document that has file_get_contents() up. I am just wondering what port i need to unblock for this to work.
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/site/videos.php on line 65
That is the warning I get from the file. Im sure it's a port issue because if there all unblocked, it works just fine. Any help would be great!
Code for file_get:
$xml = simplexml_load_string(file_get_contents('http://gdata.youtube.com/feeds/api/users/TomSka/uploads'));
To change the firewall setting as detailed in the link and it will works. Please refer below document
http://www.radiotope.com/content/safari-and-sonicwall
The setting was "Enforce Host Tag Search with for CFS"
Weirldly it only seems to affect fgets on PHP 5 running on Linux other platforms and other PHP generated HTTP requests are unaffected.

file_get_contents failing

I have a blog on tumblr, and I'm trying to access it via php and tumblrs api.
the api endpoint is:
http://blog.example.com/api/read/json?start=0&num=10&debug=1
and that seems to work fine.
However, when I do:
$result = file_get_contents("http://blog.example.com/api/read/json?start=0&num=10&debug=1");
print_r($result);
the browser outputs
Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/to/file/test.php on line 5
Warning: file_get_contents(http://blog.example.com/api/read/json?start=0&num=10&debug=1) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/to/file/test.php on line 5
This also fails with Curl.
Ideas?
I think this has something to do with the fact that my blog is on a subdomain. The reason I say this, is, if I run the same script on a blog located on the root url, it works fine. Is there a correct way to escape subdomains?
This code is failing because the DNS lookup is failing. This could be because your server is having trouble contacting its name servers. Or its because blog.example.com doesn't exist (it fails in my browser so it should fail everywhere). You could try changing your name servers to google's: 8.8.8.8 and 8.8.4.4. These DNS servers work well.
New Tumblr API: http://www.tumblr.com/docs/en/api/v2
If you have your domain with your tumblr account it will work. An example

Webpage testing on local machine

I am trying to test my webpage files on my local machine. My index page's url is as follows: http://localhost:81/indexPage.php (I use port 81 instead of 80 since my database is on Wampserver). Although I am able to access my database with phpmyadmin, when I open my index page in the browser, I get the following php error message: "php_network_getaddresses: getaddrinfo failed: No such host is known"
What changes do I need to make in order for my page to access the DB?
I think you can add a port number where you make the connection to the database.

PHP file_get_contents() does not work after uploading to the webserver

Sample code:
$html = file_get_contents('http://www.google.com');
echo $html;
It works on localhost. But after uploading to the webserver, it gives me a warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution. If I replace the domain name with google's IP address, it gives a warning: failed to open stream: Connection timed out.
And ini_get("allow_url_fopen") return 1.
===
Edit: Probably it is a server problem. I guess this question should be asked on serverfault.com.
Your host is most likely refusing the outbound connection. It's the only thing I can think of.
This is a known bug in some versions of PHP. Tell your host about the problem and ask them to upgrade PHP.
It's also possible that your host have extremely naive firewall rules in place blocking just about any networking you try to do. Which host is it?

Categories