I am trying to send post request to a website with port configured. http://example.com:8080/. When i send the request, it show some error
http.post('example.com:8080/apps/api.php', body: {'name': 'doodle', 'color': 'blue'}).then((response) {
print(response);
});
Unhandled Exception: SocketException: Failed host lookup: 'example.com' (OS Error: No address associated with hostname, errno = 7)
The port is ignored there. Is there any way i can do to fix this? Or is there any other http library that i can use?
This is probably not a port issue. Make sure you set the correct permissions in the Android manifest file (android/app/src/main/AndroidManifest.xml) to be able to make HTTP calls from your Android app:
<uses-permission android:name="android.permission.INTERNET" />
More details on that here and the official documentation from Android on permissions here.
If you have added this line
<uses-permission android:name="android.permission.INTERNET" />
at android/app/src/main/AndroidManifest.xml
then try restarting emulator or computer itself.
In my case, I restarted my laptop and it was fine. Most of the times restarting computer will solve the problems like this.
Related
I don't Know The Problem
enter image description here
Check whether you have internet connection or not.
Check if you have <uses-permission android:name="android.permission.INTERNET" /> in your AndroidManifest.xml
If you are using emulator, make sure emulator has internet connection
I'm trying to connect to Ant media webrtc server wss://abcd.com:1234/demoApp/websocket. However it always throws.
de.tavendo.autobahn.WebSocketReader: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
de.tavendo.autobahn.WebSocketWriter: Socket is closed
I'm using ant media webrtc framework sample android example and changing the URL. It worked fine with test server of antmedia
wss://test.antmedia.io:5443/demo1234/websocket(URL changed for security purposes)
However I was never able to connect to the main server. This is the code at android which I'm using to connect with server.
webRTCClient = WebRTCClient(this#LiveSessionActivity, this)
webRTCClient.setVideoRenderers(mLiveSessionBinding?.pipViewRenderer, mLiveSessionBinding?.localGLSurfaceView)
webRTCClient.init(ANT_MEDIA_URL, mLiveSessionViewModel?.streamKey, IWebRTCClient.MODE_PUBLISH, "null", intent)
Any help is much appreciated. Thanks!
It's known issue in v2.2.1. You need to set chain.pem file to Ant Media Server. Here are the instructions:
Copy chain.pem to conf.
sudo cp /etc/letsencrypt/live/your_domain/chain.pem /usr/local/antmedia/conf
PS: Please change your_domain to your domain address.
1- Add this line
http.ssl_certificate_chain_file=conf/chain.pem
after
http.ssl_certificate_file=conf/fullchain.pem
in /usr/local/antmedia/conf/red5.properties file.
2- Add this line
<entry key="SSLCertificateChainFile" value="${http.ssl_certificate_chain_file}" />
after
<entry key="SSLCertificateFile" value="${http.ssl_certificate_file}" />
in /usr/local/antmedia/conf/jee-container.xml file
I am trying to resolve IPv4 and IpV6 from ".local" using multicast DNS and I tried https://github.com/posicks/mdnsjava but it unable to resolve required ipv4/ipv6. Alternatively, I found one app which work for me but have no idea how it works.
App Link : https://play.google.com/store/apps/details?id=com.dokoden.dotlocalfinder
Also I am trying to resolve ".local" using Linux Terminal -
Command used to resolve ipv4
avahi-resolve-host-name abc.local -4
Command used to resolve ipv6
avahi-resolve-host-name abc.local -6
and it resolved successfully.
I am tried same command in Android to resolve ".local" but getting Cannot run program "avahi-resolve-host-name": error=13, Permission denied
I am trying this piece of code in Android -
Process process = Runtime.getRuntime().exec("avahi-resolve-host-name abc.local -4");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
Log.d("OutPut",in.readLine());
Finally, I got success.
I resolved Ipv4 and Ipv6 using mdnsjava dependency i.e.
implementation "xyz.gianlu.mdnsjava:mdnsjava:2.2.1"
For resolving Ipv4 I use this code snippet
for (Record record : new Lookup(localName, Type.A, DClass.IN).lookupRecords()) {
if (record.getType() == Type.A) {
((ARecord) record).getAddress().getHostAddress();
}
}
Before writing this code snippet you have to put MuticastLock on connected Wifi using
WifiManager.MulticastLock multicastLoc = wifiManager.createMulticastLock("mDnsLock");
multicastLoc.setReferenceCounted(true);
multicastLoc.acquire();
and after getting ip release multicastLock.
For Ipv6 I used same Ipv4 code snippet only here the record type should be Type.AAAA in place of Type.A
This code works up to Android 10.
I am not 100% this will work, but as comment is was to large.
check the following permissions in your AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Following links might be usefull:
How to get IP address and names of all devices in local network on Android
https://developer.android.com/guide/topics/connectivity/wifi-scan
https://github.com/stealthcopter/AndroidNetworkTools
I've followed Amazon's Getting Started guide, and (after Exporting the Amazon library, increasing the heap size available to Eclipse and adding the necessary permissions to the application manifest), I now have the sample S3_UploaderActivity Android app running.
However, when I try to upload an image I get this error message on my device's screen:
Unable to execute HTTP request: Unable to resolve host
"my-unique-namexxxxxxxxxxxxxxxpicture-bucket.s3-us-west-2.amazonaws.com": No address associated with hostname
Although this wasn't mentioned in the Getting Started guide, I presumably need to change the "my-unique-name" and "picture-bucket" strings (the latter which is stored in a constant called PICTURE_BUCKET).
But what do I change these values to??
Did you add the internet permission to your manifest file ?
<uses-permission android:name="android.permission.INTERNET" />
I am currently working with apache commons in my Project to gain access to my FTP Server.
Uploading a file is no problem at all, but If I want to download a file, I get an UnknownHost Exception what is strange because it is the same ftp server.
client.connect("ftp.liamissimo.li.ohost.de",21);
client.login("XXX", "XXX");
client.enterLocalPassiveMode();
This code works like this for uploading, but if I use it to download I got an UnknownHost exception.
I had a problem like this and I got it to work by using the IP of the hostname instead of the actual hostname...
check permissions in manifest file.
uses-permission android:name="android.permission.INTERNET"/>