I have one android application to be made.
In the Registration process i have to fill in two fields
Phone number
Name
Along with these two fields i have to also send my deviceid, current time and OS version dynamically.
How can i do so?
My Web Service is
http://frapp.badoniya.com/webservices/register.php?username=Vijay%20&deviceid=12345&mobile=98XXXXXXXX&platform=Android&os_version=4.0
Please give me a step wise solution.
Because i am very new in programming.
Use an AsyncTask to achieve what you are looking for. Here are few examples on how to use an AsyncTask, Send a GET request and Sending a POST request. For this scenario you must send a GET request.
GET Request
Example 1
Example 2
POST Request
Example 1
AsyncTask
Example 1
you have to use an AsyncTask and inside the async task you can use HTTPPost or HTTPGet requests to call a webservice using parameters
Related
I am new to android and working on an application,I am making the webservice request from android app and website,I want to track that webservice request whether it is coming from mobile app or website?So is there any way to differentiation it from the webservice request?Without using "user-Agent" in the header or without adding any value explicitly?
want to track that webservice request whether it is coming from mobile app or website?
You need to add one parameter in request header and define your device type there and same thing should be read at the server end.
First, construct an API that will service the request between the user and the client. Then test using jsonlint or Postman to determine the JSON key-value pairs..
I have a simple page that updates itself and generates a response in XML.
http://www.bmfbovespa.com.br/Pregao-Online/ExecutaAcaoAjax.asp?CodigoPapel=PETRK14|petrw14
I wonder how do I consume this page every 1 min showing these variations to the user in Android, i need the GCM or some other tool to push or is not necessary in this case? I've read all about the GCM and as I already have a WebService HTTP i would not need to configure another server.
I appreciate the help, thanks.
Hi i am new to android programming and i would like to know how to call a web service and pass parameters to the web service to obtain the return result in form of an XML.
I previously used Ksoap lib and SOAP request but thats not working correct so now i am trying the HTTP method.
Please Help
You will want to read up on the Apache HttpClient.
Beyond that its a matter of making sure the device and server are generating messages that the other side can correctly parse.
Is the server an existing service? Or are you designing that as well?
check the following in which you will use HTTP post request & you will get response in the form on XML
Android HttpPost: how to get the result
I am currently working on building an Android app for my Rails backend.
I created api_tokens_controller to create an api_token when user logs in from Android using HttpPost and save that token both in Rails user table and Android shared preferences. I was able to verify this.
I am trying to send the api_token as params[:api_token] from my Android app with every subsequent request after initial log in and have Rails verify:
In User.rb:
def self.authenticate_with_api_token(api_token_from_mobile)
user = find_by_api_token(api_token_from_mobile)
if user.nil?
return nil
else
return user
end
end
if user exists, then send other data as JSONObjects.
I am running into trouble conceptually here. I am now trying to have the Android app go to
...:3000/users and HttpGet user data as JSONObjects. The problem is that I don't know how to send the api_token from Android app to Rails in HttpGet. I am assuming that since it is RESTful, my HttpRequests have to correspond to the way rails routes work.
Questions:
Is it possible to send in JSONObject of params[:api_token] from android app to Rails in HttpGet?
Do my HttpRequests have to correspond to the RESTful way Rails works or can I just only use HttpPost?
Thanks
If I understand you correctly, then you just want to add the API token to as a URL parameter if using GET, so something like:
...:3000/users.json?api_token=token
This will put the api_token in the params hash just the same as POST data would be. The RESTful way would be to use GET for retrieving data from the API and using POST to send data, i.e. changing data on your backend but if you are going to be returning a user with the request then GET is the correct method to be using anyway.
I'm a former Ruby on Rails developer myself.
I agree with Tom that you can just pass in the api_token as a parameter with an HTTP GET.
For your second question, I'd say that the RESTful way is to use all the HTTP Verbs for the different actions that you can take in the API. You could change your routes to use HTTP POST and then supply extra parameters to differentiate between say Create and Update (to emulate a PUT). However, I don't think that's the way forward.
However, the good news is that whether you use HttpClient or HttpUrlConnection in your Android app, you will have access to the different HTTP verbs you need. For HttpClient, it is actually different classes like HttpGet, HttpPost, HttpPut and HttpDelete which you then configure by supplying URL and other parameters. For HttpUrlConnection, you just call it like so:
setRequestMethod("PUT");
Here's the relevant documentation on HttpUrlConnection:
HttpURLConnection uses the GET method by default. It will use POST if setDoOutput(true) has been called. Other HTTP methods (OPTIONS, HEAD, PUT, DELETE and TRACE) can be used with setRequestMethod(String).
I am developing an android app where a user has to enter his login details for authentication...the app will then check username and password entered by user on server and will act accordingly..so how to pass these login details to server..and do I need to implement web service on server side or can use servlet?
Can anyone please tell me which Web Service should I use for the above purpose...also I need to send other data from my client app to server, process it on server and give back the reply to client app...also how to implement a web service? Are there any tools for it? Any tutorials would be of great help.
Thanks in advance...
well, to send data to the server you can use HttpPost and HttpGet requests.
and as you need to get results from the server then, yes you'll need a web service.
You can use servlet (or) webservice, any service, as long as it can be accessed through URL. Make sure the servlet/webservice returning XML/JSON (one of these two formats are preferred, you need to code your servlet/service to return response in one of these formats) response when you hit the URL in internet explore. Once you make sure URL is returning data, then
1) In your app, using HTTPClient, invoke the URL
2) You will get either XML/JSON
3) If it JSON, use in buit JSONObject to parse the response and get the data
If response is XML, use either SAX/Dom parsing to parse the response.