Host is unresolved: api.twitter.com:80 - android

I am implementing twitter for android. When i am requesting for Request Token. It throws me this error:
04-27 11:25:01.163: DEBUG/ERROR=(3467): Host is unresolved: api.twitter.com:80
Before it was working fine. Suddenly it started giving this error.
Thanks in advance, aby

That sounds like a DNS lookup error. If you have a network tool suite installed that allows nameserver lookups (GTech Net Tools is one of these, and it's free) try entering api.twitter.com to see if your emulator can resolve the IP address.
One other thing to note is that you should be using HTTPS to call the OAuth resources at Twitter. From the :80 on your request, you can tell that whatever called oauth/request_token used plain old HTTP. All network communication involved in negotiating your OAuth tokens should be secured.

I understand that we can use HTTP as well(If your system lacks a security cert). You can tell the library to use HTTP call by adding the following line before the initializing the Twitter connection object.
System.setProperty("twitter4j.http.useSSL","false");

I had the same problem and after many tries it seems that the problem was in the emulator.. when trying the program on 1.5 it worked. However, it didn't work on 2.1. I opened the native emulator browser on 2.1 and it failed to load the google page (probably the emulator got an internet connection problem)

Related

Axios Network Error in React Native with Expo in Android

I'm trying to run an API call in React Native on Android with Expo using Axios, but I'm encountering a network error. I tried some solutions, but nothing seems to work. This is the error displayed in the console:
Network Error
at node_modules\\axios\\lib\\core\\AxiosError.js:3:0in \<global\>
at node_modules\\axios\\lib\\adapters\\xhr.js:138:8 in handleAbort
at node_modules\\event-target-shim\\dist\\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
at node_modules\\react-native\\Libraries\\Network\\XMLHttpRequest.js:647:10 in setReadyState
at node_modules\\react-native\\Libraries\\Network\\XMLHttpRequest.js:396:6 in didCompleteResponse
at node_modules\\react-native\\Libraries\\vendor\\emitter_EventEmitter.js:150:10 in EventEmitter#emit
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:417:4 in callFunction
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:114:6 in guard$argument_0
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:368:10 in guard
at node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:113:4 in callFunctionReturnFlushedQueue
I tried changing the localhost in the API link to my IP address, as well as to 10.0.2.2, but nothing worked. I checked my internet permission in AndroidManifest and made some other permission changes to the file, but nothing seemed to resolve it. I hope to find a solution to the problem soon.
if you are using a tool like expo go, [axiosError: Network error] is simply an error saying that the api you provided may not be reached.
so if you want to pull data from a local storage instead of cloud storage ... you may create a server like for example php artisan serve then create an Ngrok server for that server , afterwards take the link you received from the ngrok then use it as your new API endpoint
i m the same problem. you found solution l

Android websocket client SSL error when connecting to server running multiple SSL enabled web applications

I am working on the Android client implementation that connects via websocket to a server. I've just enabled HTTPS on the server instance and now I am receiving this issue:
W/System.err: com.neovisionaries.ws.client.HostnameUnverifiedException: The certificate of the peer (CN=otherdomain.com) does not match the expected hostname (domain.com)
at com.neovisionaries.ws.client.SocketConnector.verifyHostname(SocketConnector.java:171)
at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:126)
at com.neovisionaries.ws.client.SocketConnector.connect(SocketConnector.java:83)
at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2152)
at com.neovisionaries.ws.client.ConnectThread.runMain(ConnectThread.java:32)
at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)
It seems that the websocket client is finding mismatched server host names.
Some other related info:
otherdomain.com is a different one of our URLs. It is pointed to separate instance of the same web application running on the same server as domain.com which is the app I am currently working on.
My code is logging the URL that it is connecting to and I can see that it is correctly referencing domain.com:
connecting to: wss://domain.com?session_key=TheCorrectSessionKey
As noted otherdomain.com is another instance of the same web application. That instance already previously had HTTPS enabled and everything is working properly with that instance. The same client code I am using now is able to connect successfully to this instance.
The same web application has a front end page that also connects to the websocket via wss://. This is working properly in both Chrome and Firefox browsers for domain.com, as far as I can tell the only client having issues is the Android client, and it's only the domain.com variant of the app having issues, the otherdomain.com one seems to be working fine.
I found this issue opened on the library I am using for websockets. But I'm not 100% sure if my problem is related to it, but it may be. In particular someone states:
Not being able to connect to a WebSocket-enabled server domain unless it is also configured to be the default server on the website.
I assume only one site can be default, and perhaps otherdomain.com got set to default since it was completed first. This is all a bit over my head though to be honest, I'm not sure if this is relavent or not.

AVD not able to connect to the internet?

I've tried running an app that fetches JSON data from the internet through an HTTP Request object, It showed
java.net.UnknownHostException: Unable to resolve host “api.github.com”: No address associated with hostname
as the Exception for every trial. Later I checked the internet connectivity in the AVD by running a browser. I wasn't able to access any site.
Is there any settings that I'll have to change in the AVD Manager so that I can access the in the Internet through the Virtual Device.
Help me out, Thanks in Advance.
If that is your exact error, I see what's wrong just from that.
Android API's, unlike any modern browser, requires explicit declaration of http or https.
You have to make sure the URL contains either of those protocols which you either can do by adding it into the URL manually, or adding this code before you create the volley request:
if(!url.startsWith("http://") && !url.startsWith("https://")){
url = "http://" + url;
}
You could replace it with HTTPS, but not all sites have https, so it's a generally good idea to default it to HTTP to not get errors from that. If you supply https but there's no HTTPS certificate, the website will most likely refuse the connection.
In my case , I received such error when the Emulator could not connect to the internet.
(Try browsing the internet using the Emulator to test its internet connection. suggested in https://teamtreehouse.com/community/unknownhostexception-unable-to-resolve-host-apidarkskynet-no-address-associated-with-hostname)

Cordova - Android HTTPS requests fail on 4G

I've created Cordova Android app, and I'm facing this issue:
When on 3G/4G, whenever I try to make request towards my server I get the error:
ERR_TUNNEL_CONNECTION_FAILED.
When I am on WIFI everything works fine. This is not happening on all Android devices, I am facing this issue on Samsung Galaxy A5 (nd some other Androids).
I've discovered that if we use HTTP instead of HTTPS everything is fine.
Also according to https://www.sslshopper.com/ssl-checker.html
and
https://www.digicert.com/help/
everything seems to be fine with our SSL cert.
How can we solve this issue?
This usually happens because your provider is configuring a proxy in your device.
Try checking your current APN setting and deleting the fields proxy and port from it.
This also can be caused if you are using a port different from 443
I wonder if you have found your answer or not, but still want to post answer for others looking for the solution: Note that Cordova doesn't allow https calls to Servers with untrusted ssl certificate installed on them. You can ignore this error and continue by making a small change in a cordova file.
Open “\cordova\platforms\android\CordovaLib\src\org\apache\cordova\
CordovaWebViewClient.java”. In 'onReceivedSslError' method, comment
the else part and add handler.proceed() instead.
This issues happens with mobile data connection because the default Access Point that came with carrier generally have proxy that will not allowing SSL Tunneling. All you have to do is to set Proxy and Port to nothing.
Also ensure to use only port 443 for HTTPS.

How to debug http calls on Android devices?

I'm writing a Lovefilm client for Android, and it's not going too badly except I keep having problems with the remote calls to retrieve data from the API.
Does anyone have any tips for debugging remote calls like this? Can I tcpdump on Android or is there a native way of doing it?
For example, I'm using the Scribe-java library for OAuth to access the Lovefilm API, I can authenticate find and retrieve a list of films on the users account fine when the device is running Gingerbread, but trying to retrieve the accessToken on Froyo causes a blank response & and apparent response code of -1, I'd like to be able to see what's going on under the cvers their.
Another example I'd like to be able to the raw http for is trying to run a search, I get and IOError that says "Received authentication challenge is null"
I've used Fiddler (http-proxy for debugging http calls) with the android emulator in these cases. Just start the proxy, and start the emulator with the correct proxy address (-http-proxy ).
Fiddler is the most useful option. On the emulator #Scythe answer will work, but on a real device you will need to set the proxy in the Apache Http Client. The following code will do that:
HttpHost proxy = new HttpHost("youripaddr", 8888);
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
If you are using https, fiddler is not so useful. In that case can enable the build in logging support in Apache Http Client. The following code does that:
Headers only:
java.util.logging.Logger apacheHeaderLog = java.util.logging.Logger.getLogger("org.apache.http.headers");
apacheHeaderLog.setLevel(java.util.logging.Level.FINEST);
Headers & Wire:
java.util.logging.Logger apacheWireLog = java.util.logging.Logger.getLogger("org.apache.http.wire");
apacheWireLog.setLevel(java.util.logging.Level.FINEST);
Note that this will have to have a java.util.logging Handler configured at finest level and the default handler is configured to log to logcat, which will filter DEBUG (finest) entries by default.
If your system can share the wi-fi connection you should be able to route packets from any device through your system and then using wireshark you can get monitor your calls or get a tcpdump.
Also , and more importantly , it would be best if you log your network calls and responses as suggested by #Matthew
Windows 7 wi-fi connection sharing : http://www.winsupersite.com/article/faqtip/windows-7-tip-of-the-week-use-wireless-hosted-networking-to-share-an-internet-connection-wirelessly.aspx
Since I always run into similar troubles and it seems a lot of people having the same issues over and over again I wrote up a quick tutorial for debugging client-server communication by using netcat and cURL.
That of course only works for the simplified case that you always 'fake' on side of the connection.
For eavesdropping you can use tools like tcpdump or Wireshark. Which will definitely be easier if you're able to run the server instance directly on your local machine.
Stetho is a great tool from FB which helps in debugging android Apps. You can have access to local data and have a check on your network using this.
http://facebook.github.io/stetho/

Categories

Resources