-1

I am searching for some advise concerning the following situation:

I currently use a HttpsUrlconnection (SSL) to 'successfully' login to a website, the data I need to fetch is JSON (below screenshot as an example).

enter image description here

The login procedure is as follows:

  1. Perform a GET to grab the (set-cookie) headers (which are 2, JSESSIONID, PD-S-SESSION-ID)
  2. Perform a POST with my credentials (including these 2 cookies)
  3. Perform a final GET to retrieve the HTML page (login response is no JSON)
  4. Grab the customerID which is hidden/provided in the HTML reponse string (only after a successfull login), the ID is needed to be able to grab the actual JSON data which I am looking for.

Due to the fact that the actual data I need is provided in JSON and I still need to start writing the parsing code, I was wondering if I should switch to volley/retrofit as these 2 are much faster then httpurlconnection. I already did some research/code lookup on StackOverflow and the INet about volley/retrofit but I can`t seem to find good examples to perform the login procedure (which I need to do).

Questions so far:

  • the website uses redirects (302), can volley/retrofit handle these? Was planning to use 'com.mcxiaoke.volley:library:1.0.19'
  • there are 2 set-cookie headers, volley is only able to save 1 set-cookie header (other are overwritten?)
  • how to combine a GET, POST and a final GET in volley/retrofit? I only could find examples of 1 GET, 1 POST at the same time. I was planning to use a singleton, as the app constantly should be connected to INet.

My actual problem is to rewrite the login code which I have (HttpsUrlConnection) to volley or retrofit (how to handle the set-cookies, redirects, combine the GET and POST methods which are needed). The actual parsing of the JSON data (once logged in), should be no problem.

Not to be misunderstood. I am not asking to write me some example code. I am just looking for some good guidelines/examples? And is it worth to upgrade/gain the 60-70% speed increase which volley/retrofit should have?

Or should I save the trouble and just stick to my working HttpsUrlConnection asynctask?

Thank you in advance for your advise.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Simon
  • 1,691
  • 2
  • 13
  • 28

2 Answers2

0

Look for retrofit guidelines and usages: http://square.github.io/retrofit/
If you want to use retrofit2 then do see the imp changes from retrofit-1.9 https://futurestud.io/blog/retrofit-2-upgrade-guide-from-1-9

Deepak Sharma
  • 417
  • 3
  • 9
0

Combining POST/GET requests in Retrofit2 is easy (you can call them synchronously or asynchronously), read tutorials. If you planning to use Retrofit as your main REST client in future projects, you may also look at RxJava support (combining requests is beautiful there), but it needs some time to fully understand and "feel it".

Retrofit can handle redirects, cookies also shouldn't be a problem. To be precise, it's not really a Retrofit issue, but OkHttp client on which Retrofit is based on. You will also need to setup CookieManager and CookieStore. Useful links: 1 2 3 4 5

So... Retrofit can handle all your tasks, but it's hard to say if it will be working faster. If you planning to rewrite only this login module and your current code works, I'm not sure whether it's worth to switch to another library. Unless that login time is really long and unacceptable than give it a try (please share with us later if it helped).

rafakob
  • 3,946
  • 3
  • 26
  • 36
  • many thx for your response. Actually I am busy with getting volley + okhttp to work but ran into some trouble, the login indeed requires certain params formatted and does not return a JSon object, I refer to my question: http://stackoverflow.com/questions/36157933/volley-post-request-not-working. I was actually thinking of dropping this as I already have a working login code but as the acrual data I need is JSon I want to get this working with volley + okhttp. – Simon Mar 22 '16 at 22:42
  • I accepted your answer as it brought me on the right track, amoung using the persistentcookiestore. Although I used volley + okhttp to get a sucessfull login. Working code: http://stackoverflow.com/questions/36157933/volley-post-request-not-working Thx again. – Simon Mar 23 '16 at 16:00