Posting Data To Sub-Domain URL on Localhost - android

Hello I am building my first android app, I am currently trying to post data to a URL on my local server. When I try with my live server it works however with my local server it does not, nothing happens at all, I get no response.
This is the route in my app on my localhost: http://admin.website.dev
I changed my hosts file and virtual host configuration on my localhost so that any address with the extension ".dev" points to a folder on my localhost. eg. "localhost/website"
Is there a reason this does not work in my android app when I try posting data?
I have already added the INTERNET permission in my manifest file.

Since android 5, you need to make a POST on DNS valid URL.
I'm not sure if your changes on hosts file will work.

Related

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)

Android: Access http server instead of https in vector (Android Matrix client)

I'm using vector (It's a Android Matrix client Download link:
https://github.com/vector-im/vector-android). This Vector is using
the https server (https://vector.im and https://matrix.org as home
and identity url's) but i want to connect my local matrix server
using http not https.
For this i edited the strings.xml (id's are vector_im_server_url,
matrix_org_server_url, default_hs_server_url,
default_identity_server_url) file with my local http server.
In this case i'm getting the toast message as "Unable to login :
failed to connect to XXXXXX.XXXXXX.com/XXX.XXX.XXX.XXX (port 8008)
after 15000ms". can anyone help where to change this setting
Note:
Initially i'm not able to access the local matrix server url in my system browser for this i added server details in C:\Windows\System32\drivers\etc\hosts after that i'm able to access it in my browser
I think you missed my answer on #matrix:matrix.org. I tried to connect to your homeserver on port 8448 and 8008 from the public internet and the server was not responding. It looks like you need to open up your firewall on those ports. Please try asking again in #matrix:matrix.org (bearing in mind that the core matrix team are awake on european timezones).
Edit: As per https://vector.im/develop/#/room/#matrix:matrix.org/$147222237811409Apqfi:matrix.org, the server really was inaccessible when we tried to give you support earlier. Glad you've got it sorted now; you should also be using the same HS url for both 'vector' and 'matrix' HS URL otherwise it will try to fall back to using matrix.org for unrecognised users. Thanks for the downvote...
M
By using https server only we can use vector services. So, i changed strings.xml as like this
<string name="vector_im_server_url">https://matrix.org</string>
<string name="matrix_org_server_url">my_local_https_server_url</string>
<string name="default_hs_server_url">my_local_https_server_url</string>
<string name="default_identity_server_url">https://matrix.org</string>
to know these url's open your local https server url in browser. It will show Home Server and Identity Server as shown in the image and paste Identity Server url in vector_im_server_url and default_identity_server_url then Home Server url in matrix_org_server_url and default_hs_server_url

Android APK from Rails Server

I've stored my .apk file in my rails server. I've set up a route that redirects a given url to a method that essentially sends the file
in my routes.rb file
match '/myApk.apk' to: 'upgradeapk#index'
Upgradeapk_controller.rb file
def index
#filename = '/myApk/myApk.apk'
#tmpfile = 'upgradedApk.apk'
send_file(#filename, :disposition => 'inline', :stream => true, :type=> 'application/vnd.android.package-archive', :file_name => #tmpfile)
end
When i type my sever url and add '/myApk.apk' it starts the downloading process as long as i do it on my a computer. However if i try to do it on my android device it doesn't work. Checking the download lists in my android device browser i notice that the download "job" for the apk is created, however its in an endless loop changing between states "in queue" and "downloading". Nothing ever downloads.
Do I have to set the send_file differently when it comes to making it work on android devices?
----EDIT------
Ok so i've decided to store the files in a dropbox location instead of storing it in my server. If i pass the url for the file directly in my android function for the http request, it works well. The file is found, downloaded and the installation is prompted.
class UpgradeapkController < ApplicationController
def index
android_apk = Androidaplicacion.first (Model to access the table in which i store the apk dropbox url)
route = android_apk.url
redirect_to route
end
end
I've set up my controller to redirect to the given url for the dropbox file. If i try the url (same as before, using the "match" url) in my android browser, this time it downloads. However, if I try it from the android app, its the same as before, it just doesnt download.
So, the "send_file" method seems to not be working if its on the android platform. redirecting to my dropbox url from the controller works on android but only from a browser, not using the http request on my android app. The only way to get it to work in my android app is if I use the dropbox direct link.
Also, I first thought this was because my server was running on https and the certificate its not a valid one. I found a way to bypass the https certification encryption/certificate validation thing on my android app but it didnt work either (it appeared to have succeed in avoiding the validation) but the results ended up been the same. I then ran an instance of my server using http and still same results.

Phone can't connect to PC to execute PHP file

I created a database in my PC, and now I want to retrieve all table data and display them on my phone usin Google gson library by executing a php file in the server. The problem is the phone can't connect to the PC to execute that php file:
Error 403 for URL http://192.168.1.2/android_connect/get_all_products.php
I'm sure that the code is working cause i tested with that online link and data are retrieved in the phone.
The url is like that in JAVA code:
String url = "http://192.168.1.2/android_connect/get_all_products.php";
Is that correct? Is there something to do to let the phone connect to the PC?
Thank you for helping.
You need to tune your PC's configuration to allow remote requests. Please see what error 403 is. It'd also help to check what's in your HTTPD logs concerning this request.
To allow remote access to apache on Windows change the file: c:\wamp\bin\apache\Apache2.2.22\conf\httpd.conf
You need to allow remote access to directory C:\wamp\www like this:(add that lines)
<Directory "C:/wamp/www/">
Order Deny,Allow
Allow from all
</Directory>
And RESTART YOUR SERVER.

Android emulator cannot connect with local tomcat server with HttpURLConeectioin

I'm doing a project to connect Android with local Tomcat server. But now I'm facing a problem for about 1 week. Who can help me..Thanks very much!
I use the newest android API and Tomcat 7.0. When I start Tomcat server. I can access the Tomcat homepage through emulator browser with url:(http://10.0.2.2:8080). But when I use HttpUrlConnection in the code. I cannot get the successful connection. I also use httpurlconnection to access www.google.com and www.android.com. I cannot connect them either.I use HttpURLConnection.HTTP_OK to see whether it make a successful connection. I also see the Connected is false for HttpURLConnection instance I make.
By the way I also add the internet access permission for it in AndroidManifest.xml before tag.
Thank you very much! Help me. It's emergency.
I recently had this problem. As mentioned above, (on Windows) start cmd, and use ipconfig to find the PC's IP address. Also, due to my Eclipse/Tomcat configuration I needed to have my Eclipse project name in the URL. The URL I used was like this: http://192.168.1.2/myEclipseProject/ServletName
Also, you may need to add the port to the ip address, if your Tomcat still has the default configuration: 192.168.1.2:8080

Categories

Resources