my url for json does not work - android

every time i try to print json file from my wamp server it doesn't work
i use this URL "http://127.0.0.1/webapp/users.php" to acsess the json data
but when i put another link like "http://api.androidhive.info/contacts/"
it works perfectly , so i don't know what is the problem exactly
i'm just starting to learn about json parsing in android .
any help?
my php code is
$row['id'],
'username'=>$row['username'],
'password'=>$row['password'],
));
}
print json_encode(array('result'=>$result));
mysqli_close($conn);
?>

Of course i wont work, this address is local address for your own work station(computer or any device with a ip address eg, your own phone as that address) that is why it is local ip address. Only your system can read and write to it. To over come this dilemma , either one host your on a server, or go the cheap way and broadcast your ip address to the internet using a tunneling software such as ngrok.
Here are some advantages:
Don’t constantly redeploy your in-progress work to get feedback from clients. ngrok creates a secure public URL (https://yourapp.ngrok.io) to a local webserver on your machine. Iterate quickly with immediate feedback without interrupting flow.
Test mobile apps against a development backend running on your machine. Point ngrok at your local dev server and then configure your app to use the ngrok URL. It won't change, even when you change networks.
Building webhook integrations can be a pain: it requires a public address and a lot of set up to trigger hooks. Save yourself time and frustration with ngrok. Inspect the HTTP traffic flowing over your tunnel. Then, replay webhook requests with one click to iterate quickly while staying in context.
Host personal cloud services on your own private network. Run webmail, file syncing, and more securely on your hardware with full end-to-end encryption.
ngrok is easy to install. Download a single binary with zero run-time dependencies for any major platform. Unzip it and then run it from the command line.
After reading and deliberation on some links i received at the courtesy # cricket_007, there is another way to access your local ip address across the network from wamp server.
try this, it works its just a bit longer to setup vs ngrok thats very easy, try the option thats work for you.
Happy Coding :)

Related

MongoDB error: can't call something /127.0.0.1:27017/admin

I am trying to connect to mongodb through an android application, Mongodb is running in local
MongoClient mongoClient = new MongoClient();
DB db = mongoClient.getDB("dbname");
I am getting the error as can't call something: /127.0.0.1:27017/admin
mongodb is running at the back.
I wanted to know why admin?? There is no collection like admin in my DB.
When I connect using the command line, it works, and I am able to insert and query data.
I don't know what is going wrong. Nothing has been mentioned in the examples I have browsed so far about any kind of configuration that needs to be done.
Kindly help!!
Since you are running your application in Android, I would implicitly assume your MongoDB server must be running somewhere else on a different ip address that is not 127.0.0.1. By default, in absence of hostname / ip address, MongoClient tries to connect to localhost loopback address of 127.0.0.1 on port 27017 (default port until something else is specified), and fails because there is MongoDB server instance running on the localhost. I would suggest following:
Look into details of where your server is located and get hostname / port details for it.
Look into MongoDB Java API further and some sample apps http://docs.mongodb.org/ecosystem/drivers/java/ on how to access MongoDB that is running on a different server.
As commented on your question as your client is on a different platform to the server you need to specify the full host connection rather than use the default.
That said:
DO NOT DO THAT!
You most certainly do not want your MongoDB instance accessible over the internet in this way. What you want is a web service to proxy your requests and pass them on to MongoDB. You can do that yourself or look into something that might be listed here:
http://docs.mongodb.org/ecosystem/tools/http-interfaces/
Exposing your database to the internet is never a good idea for various reasons but the two most prominent being security and firewall rules that are not going to allow traffic over certain ports. HTTP is going to be available just about everywhere and is the most useful means of communication for a mobile app.

how to use android json webserver

Hello every one I am new with servers things. I want to develop program that get data from the database on the server and it's my first time I don't have any idea of this thing.
Let say like Login & Logout:
how can i make a virtual server for testing on my PC
how can i connect the emulator with this virtual server
how can i request the data from thee database
Do I need software like Xamp or Wamp? If yes how can I use it?
I found so many examples about the json and webserver but I don't know how to make virtual server and connect the emulator to it.
as I understand this problem you need two separate pieces of software. You will need 1) server. To begin with you can install XAMP and WAMP to get Apache running. There are millions of tutorials on how to set up an Apache web server online, and to begin with you could just return a string or a simple data structure (e.g. JSON or XML). As you want to do more complex things you can learn more, but in the beginning think "easy does it". From your text I anticipate that you just want to test as a proof of concept.
- What OS do you run BTW?
Another solution is to rent some space on a server accessible from the Internet. Then you could test your server-side regardless of where you are located.
Second you would need to create a program for the android. There are several guides, but have a look here: http://developer.android.com/training/basics/network-ops/index.html. If you choose to make your data available through the HTTP protocol there are very boilerplate-like procedures for how to download and parse the data.
If you are hosting the server-side on your local computer you would need to use local addressing, but if you choose to put it online you could acquire the data from everywhere as long as you have an internet connection.
Good luck!

Android How To Simulate HTTP Communication for Offline Demo

I have an Android App which uses http communication for nearly every operation. I want to be able to demo without connection to the internet by somehow replaying the http exchange. How can this be done? So I want to somehow almost like mock objects but really mock http session so I can always demo the app on or offline. This is really a very cool thing to be able to do. Since you can demo the app easily and reliably. Does anyone know how I could do this. Replicating the whole server side is just not an options its got too much stuff. Its important not to just show screencast but the real data exchange. I just want to be able to run thru the app and replay. Maybe debug as well. Thanks
Here's a hybrid solution using similar ideas from other answers:
You could write a dead simple HTTP server that listens on "localhost:80" (or whatever the port is on the server you're targeting) and point your application to this host instead by factoring out the host name from requests. Your local server has a reference to the actual remote server and does the following:
If ONLINE, forwards the request as-is to the real server, gets the response, saves it locally either in an in-memory cache keyed by the request URL or a file named with the URL as its identifier (munged appropriately)
If OFFLINE, looks up a request in its (in-memory or file system) cache and returns the contents from the cache instead
This is kind of like the record/playback mode that #nicholas.hauschild says.
Now you can just run your app once when ONLINE, causing your localhost server to save away requests that it issues against the real server. Then when you run your app OFFLINE, it just returns these cached contents instead whenever the same URLs are issued.
Hope this helps.
If you're device is rooted, you can use tcpdump as explained in this post: http://www.vbsteven.be/blog/android-debugging-inspectin-network-traffic-with-tcpdump/
or use AndroShark (get if from xda-developers here: http://forum.xda-developers.com/showthread.php?t=725692)
or this one (wifi only): http://www.9bitlabs.com/default.aspx
I would create a "Record Mode", and a "Playback Mode" for my app.
While in Record Mode, I would write out a file each time an http request was made. The file would be named by the endpoint the request is made. The contents of the file would a collection of serialized http requests/responses broken up by line. You could then deserialize lines from this file until you find the proper request, and play back the deserialized response.
This approach would also allow you to create Record/Playback profiles, where you could record multiple different sessions (by placing the files into a different directory) and then playback from whichever profile you choose.
This whole approach could be done with a small wrapper class around the HttpClient object you are using.
One way would be to use an HTTP proxy. Redirect all web traffic to the proxy, which can be running locally on the phone. This could be done with little or no source code change.
find a way using fiddler on pc,and android app take fiddler as proxy.So the http traffic is record.
http://blog.csdn.net/grhunter/article/details/5830199
Simples solution lies in faking it when there is no connection. If there is a error in connection, make sure ur app throws some preset data rather than an error in connection thing.

Accessing localhost from android over wifi

I have written a Https webservice, so it is encrypted with SSL.
For testing i would like to acces that webservice over wifi.
edit Example: My webservice is running on a VM number 111, i want to acces it over wifi so the adress would be https://VM111/Webservice/service.svc. I can acces it from any laptop in the wifi network but not from the Android Phone, that is my problem.
Is there a way to acces the localhost of the VM, from the Android phone, and has anyone dealt with this before?
My gues is that is has something to do with domains because every other device is in the Active directory.
If there are any questions about my question i am glad to answer them,
You can get a public URL for your server running on a specific port on localhost.
At my work place I could access the local server by using the local IP address of my machine in the app, as most of the other answers suggest. But at home I wasn't able to do that for some reason. After trying many answers and spending many hours, I came across https://ngrok.com. It is pretty straight forward. Just download it from within the folder do:
ngrok portnumber
( from command prompt in windows)
./ngrok portnumber
(from terminal in linux)
This will give you a public URL for your local server running on that port number on localhost. You can include in your app and debug it using that URL.
You can securely expose a local web server to the internet and capture all traffic for detailed inspection. You can share the URL with your colleague developer also who might be working remotely and can debug the App/Server interaction.
Hope this saves someone's time someday.
I found a quick solution to this problem.
try this link, it should help you guys fix the problem.
http://www.mobitechie.com/android-2/how-to-access-localhost-on-android-over-wifi/
I only changed 1 thing, where the tutorial states you change '127.0.0.1' to 'All',
change it to the ip address your server is running on instead.
after that you should be able to connect to your localhost.
I was also looking for something similar
from desktop type ipconfig you will get desktopIP now put that in android browser you should get your localhost

Does my server need a registered domain name if it is only accessed from mobile application?

I want to develop an app for android and am a newbie to pretty much anything server related. I want my app to be able to perform simple get and post requests to my server. I don't intend on hosting a website on it and it will only be accessed by the app. Do I still need to get a registered domain name or can I directly access the ip address of my server? Obviously it would have to be able to be accessed by things other than the local network the server is on.
Thanks!
The problem with doing it with the IP address is: "What if the IP changes?". With a domain you can just update the DNS records and the app will work as expected, but if you hardcode the IP you're going to have to have everybody update it.
Look into services like DynDNS which will provide a free subdomain and manage DNS for you.
You could do it by IP address instead of using a servername, but often a static IP will cost more than $8 per year, which is about what domain names cost.
If it's not about cost, and you're more concerned with how to set up a domain name with a machine on your local network - You can get free dynamic DNS service with pretty minimal setup.
You should be able to access via IP. You just need to remember that, though highly unlikely, your IP could change without warning and your app would need to be updated. I purchased a domain name and use dynamic dns (dyndns.org) to host my zone file.
They provide you with ways to ensure that the IP is up to date.
Even in your situation, a domain name is a good idea. It makes things look more official to reviewers and insulates you in case your server's IP address changes (rather than having to re-build your re-distribute your app).
It depends on if your server is hosted on a shared IP with other servers using what are called host headers.
If you can open a browser and put http://10.10.10.10 (replace ip with your server's ip and assuming your server is answering on port 80, stock http port), and get your server to respond, then no you don't need a domain.
As mentioned above, its a bad idea though. IPs do change and having a DNS pointing to a domain is the only way to deal with it without having to force all your mobile users to update the app in the event of a change.

Categories

Resources