How to identify web request client? - android

I have a web api and 2 another apps 1 is in xamarin and another is in angularjs.
I am calling api in xamarin Using HttpClient.
I am calling api in angularjs using $http service .
Now I want to implement different logic for HttpClient call and $http call, how can I recognize the web request client?

You can use the different User-Agent or custom HTTP header when making the web request.
You can find more details here: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields

Related

HTTP Request from Web to Android

How can I make an HTTP request from a web application (like node js) to an android app?
The goal is to read if the response is a success, for example, from Web to Web I make an HTTP request to the IP/URL and, if it returns 200, I have success. It would work as a "ping" to check if the android app is "alive".
Note: I don't know apps architecture
Thanks!
Using web sockets ( example here: https://www.html5rocks.com/en/tutorials/websockets/basics/ ) will help u to achieve it

How to use django authentication(django.contrib.auth) with my Android app

I am using Django as my backend for my android app. I have been handling post request using #csrf-exempt annotation with my views as I wasn't able to deal with csrf verification while sending post request from android(VOLLEY LIBRARY).
Now, I have to use django.contrib.auth login and logout methods but sessions aren't working when I am sending post request from android.
I had tried enabling cookies with my request in android but that also didn't work(enabling cookies also did not solve the csrf verification failed issue).Also I tried taking csrf token from a GET request to django( django.middleware.csrf - get_token) and then passing that csrf token in headers(X-CSRF-TOKEN)in my post requests, that also didn't work.
Code that I used to enable cookies in android:
CookieManager manager = new CookieManager();
CookieHandler.setDefault(manager);
So,
1. I don't know how to use django scripts without using #csrf-exempt from android.
2. and how to use django login with android
Here is a generic response on using django as a backend: Is it possible to develop the back-end of a native mobile app using the python powered framework Django?
More specifically this is normally done with a JWT - json web token: http://www.django-rest-framework.org/api-guide/authentication/#django-rest-auth
I'm sure other rest/ api frameworks exist but I normally use DRF.
Here is an example with a tutorial: Authentication with android app in a django server

Account Manager + Cookie Based Authentication

Is it possible to use Android Account Manager using Cookie-based authentication? How (a code with a explanation would be much appreciated)?
I have seen many examples regarding authentication token, but that is not the case. I have just implemented cookie-based authentication on Python FLASK.
OBS.: I'm using Android Volley for the requests of the application.
All you need to do is to add this line in onCreate in your Application class:
CookieHandler.setDefault(new CookieManager());
this line will make your HttpUrlConnection hold cookies like browser, and since most of the http agents like Volley or okHttp are based on HttpUrlConnection they also will hold your cookies )

Android call my own LOCAL WebService (Symfony) in localhost

i have build an app on Symfony and a WebService REST for this app.
I have already build an Android application on the same idea of my Symfony project and i want to use the API (I'm on localhost) of my Symfony Application for consuming my Webservice in Android.
How can I do that without an OVH server or something else ?
Thank you ;)
You just need to send HTTP request to your webservice by specifing the endpoint as your local IP address.
You can use a third-part library as https://github.com/square/retrofit to do that properly, or with the native android http request manager : https://developer.android.com/reference/java/net/HttpURLConnection.html

App Engine endpoint with Retrofit

Would like to use Retrofit for handling network requests between Android Client and GAE endpoints.
GAE endpoints give Client/Server endpoint libraries to handle all the networking and also Oauth2 authentication which is nice.
Retrofit helps well for asynchronous call, cancellation, parallel calls...so is better than android client asynctask.
So can this Retrofit lib be configured with Appengine GAE endpoints or need to go through normal GAE servlet?
Just to clarify my question and make answers clear for any who read this :
I had for my App :
Client side : cloud endpoint library generated by google plug in for eclipse
Back end side GAE : different API with methods coded in JPA such as :
#ApiMethod(name = "insertMyShareItem")
public ShareItemData insertMyShareItemData(ShareItemData shareitemdata) {
logger.log(Level.SEVERE, "insertMyShareItem");
}
Advantages of google cloud endpoint was endpoint libray , easy use of Auth2 and automatically use of secure connections via HTTPS
Now I want to give up Async task in order to implement Retrofit or Volley. I understood I cannot use google cloud endpoint anymore and need to transform my methods on GAE Back end side in methods which extends HttpServlet so I can access them by URL call with normal setup of Retrofit.
Which means now I need to care :
how I pass my object to Retrofit and how I retrieve them on back end
how I transform Retrofit HTTP call in a HTTPS call for secure connection
how I implement and manage Auth2 and tokens between Client and GAE back end to establish secure authentication.
This is what I understood from search and below answers.Thks
Use the Google Cloud API URL as the base URL and proceed with the normal setup of Retrofit. I don't think it is a big deal. Here is a link to a tutorial that could help you get started with Retrofit.
[source]

Categories

Resources